Name
UBound Function
Syntax
UBound(arrayname[,dimension])
arraynameUse: Required
An array variable or an expression that evaluates to an array.
dimensionUse: Optional
Data Type: Long
A number specifying the dimension of the array.
Return Value
A 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 created by VBScript code, setdimensionto 1, set it 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 and Gotchas
Note that UBound returns the actual subscript of the upper bound of a particular array dimension.
UBound is especially useful for determining the current upper boundary of a dynamic array.
The UBound function works only with conventional arrays. To determine the upper bound of a collection object, retrieve the value of its Count or Length property.
See Also
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