Variable Arrays

From GAB Help
Jump to: navigation, search

Defining an Array in GAB

V.Local.sValues.Declare(String)
'This creates an array with a lower bound(lbound) of 0 and an upper bound(ubound) of 10
V.Local.sValues.Redim(0,10)
Variables arrays can be set in the Local, Global, uLocal, Static and uGlobal name spaces
Setting and Using Array Value
One way of setting an array is:
v.local.sValues(0).set(“ME”)
v.local.sValues(1).set(“TEST”) 

Using the Function.Intrinsic.String.Split command can be an easy way to fill an array.

Using the variable transformation .LBound and .UBound you can loop through an array for processing

F.Intrinsic.Control.For(V.Local.iC,V.Local.sValues.LBound,V.Local.sValues.UBound,1)
'Processing v.local.sValues(v.local.ic)
f.intrinsic.control.next(v.local.iC) 

Redim and RedimPreserve

At any point you can redimension an array this will clear the contents of the array. However if you want to resize the array because you have additional data you can do a RedimPreserve. This will keep the array from losing the information already stored. RedimPreserve can also be used to size an array back down to only the indexes that where used.

Example

V.Local.sMachines.Declare(String)
V.Local.iCounter.Declare(Long,0)
V.Local.sMachines.Redim(0,1000)
'Connection to the database is opened
F.ODBC.Connection!conx.OpenConnection(V.Ambient.PDSN,V.Ambient.PUser,V.Ambient.PPass)
F.ODBC.Connection!conx.OpenRecordsetRO("rst","SELECT MACHINE FROM V_WORKCENTERS")
F.Intrinsic.Control.DoUntil(V.odbc.conx!rst.EOF,=,True)
V.Local.sMachines(v.Local.iCounter).Set(V.ODBC.conx!rst.FieldValTrim!MACHINE)
F.Intrinsic.Math.Add(V.Local.iCounter,1,V.Local.iCounter)
F.ODBC.conx!rst.MoveNext
F.Intrinsic.Control.Loop
'size array down to what was used
v.Local.sMachines.RedimPreserve(0,V.Local.iCounter.--)
F.Intrinsic.debug.Stop
F.ODBC.conx!rst.Close
F.ODBC.Connection!conx.Close