UBound Function
The UBound Function returns the Largest subscript of the specified
array. Hence, this value corresponds to the size of the array.
Syntax
UBound(ArrayName[,dimension])
• ArrayName, a Required parameter. This parameter corresponds to the name of the array.
• dimension, an Optional Parameter. This takes an integer value
that corresponds to dimension of the array. If it is '1', then
it returns the lower bound of the first dimension; if it is '2',
then it returns the lower bound of the second dimension, and so on.
Example
<!DOCTYPE html>
<html>
<body>
<script language="vbscript" type="text/vbscript">
Dim arr(5)
arr(0) = "1" 'Number as String
arr(1) = "VBScript" 'String
arr(2) = 100 'Number
arr(3) = 2.45 'Decimal Number
arr(4) = #10/07/2013# 'Date
arr(5) = #12.45 PM# 'Time
document.write("The Largest Subscript value of the given array is : " & UBound(arr))
' For MultiDimension Arrays :
Dim arr2(3,2)
document.write("The Largest Subscript of the first dimension of arr2 is : " & UBound(arr2,1) & "<br />")
document.write("The Largest Subscript of the Second dimension of arr2 is : " & UBound(arr2,2) & "<br />")
</script>
</body>
</html>
When the above code is saved as .HTML and executed in Internet
Explorer, then it produces the following result:
The Largest Subscript value of the given array is : 5
The Largest Subscript of the first dimension of arr2 is : 3
The Largest Subscript of the Second dimension of arr2 is : 2