Information.UBound Method (Array, Int32)
Returns the highest available subscript for the indicated dimension of an array.
Assembly: Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
Required. Array of any data type. The array in which you want to find the highest possible subscript of a dimension.
Optional. Integer. The dimension for which the highest possible subscript is to be returned. Use 1 for the first dimension, 2 for the second, and so on. If Rank is omitted, 1 is assumed.
Return ValueType: System.Int32
Integer. The highest value the subscript for the specified dimension can contain. If Array has only one element, UBound returns 0. If Array has no elements, for example if it is a zero-length string, UBound returns -1.
Since array subscripts start at 0, the length of a dimension is greater by one than the highest available subscript for that dimension.
For an array with the following dimensions, UBound returns the values in the following table:
Call to UBound
You can use UBound to determine the total number of elements in an array, but you must adjust the value it returns to account for the fact that the subscripts start at 0. The following example calculates the total size of the array a in the preceding example:
The value calculated for total is 3030, which is 101 * 6 * 5.
The following example uses the UBound function to determine the highest available subscript for the indicated dimension of an array.
Available since 1.1
Available since 2.0