5 out of 14 rated this helpful - Rate this topic

UBound Function

Updated: September 2009

Returns the largest available subscript for the indicated dimension of an array.


                      UBound(arrayname[, dimension])
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.

The UBound function is used with the LBound Function to determine the size of an array. LBound returns 0 because the lower bound for any dimension is always 0. Therefore, the length of a dimension is one greater than the output of the UBound function.

The following table shows the values returned by various UBound statements when they are applied to an array that has these dimensions:

Dim A(100,5,4)

Statement

Return value

UBound(A, 1)

100

UBound(A, 2)

5

UBound(A, 3)

4

Date

History

Reason

September 2009

Added information to Remarks.

Customer feedback.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
getting array length using UBOUND function
There is no direct function to get the length of the array.
UBOUND function returns the largest subscript of the array.
By adding 1 to the value returned by the UBOUND function you will get the length of the array.
Ex.
dim a(3)
  document.write(Ubound(a)+1)
Example for WSH

Option Explicit

Dim sFutureArray, MyArray, x, sText

sFutureArray ="Some day this example will look boring to me"

MyArray = Split (sFutureArray, " ", -1, 1)
sText = "The array holds " & UBound (MyArray) - LBound(MyArray) + 1 & " values. The values are the following:" & VBlf
For x = LBound(MyArray) to UBound (MyArray)
 sText = sText & "MyArray(" & x & ")" & VBTab & MyArray(x) & VBlf
Next
WScript.Echo sText