UBound - VBScript
Overview
UBound retrieves the upper bound subscript of an array, specifying the last index value that can be used to access the array. It is useful for determining the valid range of array indices.
Syntax
UBound([ArrayName], [Dimension])
Parameters:
- ArrayName: Required. The name of the array whose upper bound is to be retrieved.
- Dimension: Optional. The dimension of the array whose upper bound is to be retrieved. Default is 1, representing the first dimension.
Options/Flags
None.
Examples
'Retrieve the upper bound of a one-dimensional array
Dim MyArray As Integer = [1, 2, 3, 4]
Debug.Print UBound(MyArray) ' Output: 3
'Retrieve the upper bound of a two-dimensional array
Dim MyArray2D As Integer = [[1, 2, 3], [4, 5, 6]]
Debug.Print UBound(MyArray2D) ' Output: 1
Debug.Print UBound(MyArray2D, 2) ' Output: 2
Common Issues
- Incorrect Array: Ensure you specify the correct array name and dimension when calling UBound.
- Invalid Dimension: The dimension specified must be a valid dimension for the array.
Integration
UBound can be combined with other VB Script commands for array manipulation, such as LBound (retrives the lower bound) and Redim (resizes an array).
Related Commands
- LBound: Retrives the lower bound of an array.
- Redim: Resizes an array.
- Array: Defines a new array variable.