UBound Function
Returns the largest available subscript for the indicated dimension of an array.
Syntax
UBound(arrayname[,dimension])
Arguments:
- Arrayname : Required. Name of the array variable; follows standard variable naming conventions.
- Dimension: Optional. Whole number indicating which dimension's upper bound is returned. Use 1 for the first dimension, 2 for the second, and so on. If dimension is omitted, 1 is assumed.
Remarks
The UBound
function is used with the LBound
function to determine the size of an array. Use the LBound
function
to find the lower limit of an array dimension.
The following examples illustrate the use of UBound
function:
Example 1:
Dim myArray
myArray = Array(10, 20, 30)
UBound(myArray) 'Output with default Dimension -> 2
Example 2:
Dim food(1,2)
food(0,0)="Apple"
food(0,1)="Banana"
food(0,2)="Orange"
food(1,0)="Pizza"
food(1,1)="Hamburger"
food(1,2)="Spaghetti"
UBound(food) 'Output with default Dimension -> 1
UBound(food,1) 'Output for Dimension 1 -> 1
UBound(food,2) 'Output for Dimension 2 -> 2