Description
The UBound() function returns the largest subscript for the indicated dimension of an array.
Tip: Use the UBound function with the LBound function to determine the size of an array.
This function has the form:
UBound(arrayname [,dimension])
Parameter | Description |
---|---|
arrayname | (required) The name of the array variable |
dimension | (optional) Which dimension's
upper bound to return. 1 = first dimension, 2 = second dimension, and so
on (default = 1) |
Examples
The following examples show the basic use of this function:
Example 1
days = Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
Msgbox(LBound(days))
Msgbox(UBound(days))
This produces the following result (each line in a separate pop-up message box):
0
6
Example 2
A two dimensional array:
Dim food(2,3)
food(0,0)="Apple"
food(0,1)="Banana"
food(0,2)="Orange"
food(0,3)="Lemon"
food(1,0)="Pizza"
food(1,1)="Hamburger"
food(1,2)="Spaghetti"
food(1,3)="Meatloaf"
food(2,0)="Cake"
food(2,1)="Cookie"
food(2,2)="Icecream"
food(2,3)="Chocolate"
Msgbox(LBound(food,1))
Msgbox(UBound(food,1))
Msgbox(LBound(food,2))
Msgbox(UBound(food,2))
This produces the following result (each line in a separate pop-up message box):
0
2
0
3
Miscellaneous Information
Supported in Version: | 1.0 |
---|