JavaScript tutorial:
ubound method

 

Applies to: VBArray Object

The ubound method returns the highest index value used in the specified dimension of the VBArray.

Syntax

safeArray.ubound(dimension)

The ubound method syntax has these parts:

Part

Description

safeArray

Required. A VBArray object.

dimension

Optional. The dimension of the VBArray for which the higher bound index is wanted. If omitted, ubound behaves as if a 1 was passed.

Return Value

The ubound method returns the highest index value used in the specified dimension of the VBArray.

Example

If the VBArray is empty, the ubound method returns undefined. If dim is greater than the number of dimensions in the VBArray, or is negative, the method generates a "Subscript out of range" error.

The following example consists of three parts. The first part is VBScript code to create a Visual Basic safe array. The second part is JavaScript code that determines the the number of dimensions in the safe array and the upper bound of each dimension. Both of these parts go into the <HEAD> section of an HTML page. The third part is the JavaScript code that goes in the <BODY> section to run the other two parts.

<HEAD>
<SCRIPT LANGUAGE="VBScript">
<!--
Function CreateVBArray()
Dim i, j, k
Dim a(2, 2)
k = 1
For i = 0 To 2
For j = 0 To 2
a(j, i) = k
document.writeln(k)
k = k + 1
Next
document.writeln("<BR>")
Next
CreateVBArray = a
End Function
-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!--
function VBArrayTest(vbarray)
{
var a = new VBArray(vbarray);
var b = a.toArray();
var i;
for (i = 0; i < 9; i++)
{
document.writeln(b[i]);
}
}
-->
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
VBArrayTest(CreateVBArray());
-->
</SCRIPT>
</BODY>

To run the code, paste it into JavaScript Editor, save file as htm format and click the Show Interview View button.