UBound Function
Updated: September 2009
Returns the largest available subscript for the indicated dimension of an array.
UBound(arrayname[, dimension])
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 |
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)
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)
- 12/14/2010
- Machani ShreeLakshmi
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