Sometimes, you will need to find the upper and lower limits of an array. To do this you can use the LBound and UBound functions. This is especially useful if you have used the ReDim statment (see dynamic arrays). To find the upper bound of an array (ie the ... To number part) use the UBound Function, using the following syntax:
UBound(ArrayName, Dimension)
ArrayName is the name of your array. Dimension is an optional integer representing the dimension number for use when using multidimensional arrays (discussed later in this tutorial). To find the lower bound of an array (ie the number To ... part of the array) use the LBound function, using the following syntax:
LBound(ArrayName, Dimension)
ArrayName is the name of your array. Dimension is an optional integer representing the dimension for use when using multiple dimensional arrays. The following code fills a list box with the values of all the items in gArray.
' Get the lower and upper values of
gArray
LowerVal = LBound(gArray)
UpperVal = UBound(gArray)
For i = LowerVal To UpperVal
' Add a new item to the list, containing the
' next item in the array
List1.AddItem gArray(i)
Next
Comments