Name
UBound Function
Syntax
UBound(arrayname[,dimension])
-
arrayname Use: Required
The name of the array.
-
dimension Use: Optional
Data Subtype: Long
A number specifying the dimension of the array.
Return Value
A Variant of subtype Long.
Description
Indicates the upper limit of a specified dimension of an array. The upper boundary is the largest subscript you can access within the specified array.
Rules at a Glance
If
dimensionisn’t specified, 1 is assumed. To determine the upper limit of the first dimension of an array, setdimensionto 1, to 2 for the second dimension, and so on.The upper bound of an array dimension can be set to any integer value using
Dim,Private,Public, andRedim.
Programming Tips & Gotchas
Note that
UBoundreturns the actual subscript of the upper bound of a particular array dimension.UBoundis especially useful for determining the current upper boundary of a dynamic array.The
UBoundfunction works only with conventional arrays. To determine the upper bound of a collection object, retrieve the value of its Count or length property.
VBA/VBScript Differences
In VBA, the UBound function is frequently used
along with the LBound function to enumerate the
elements of an array, as in the following code fragment:
For intCtr = LBound(aArray) To UBound(aArray)
However, although VBScript supports the LBound
function, it does not allow you to define the lower bound of any
array. As a result, there is never a reason to call the VBScript
LBound function.
See Also
| LBound Function |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access