The ubound function in JavaScript USES an instance

  • 2020-03-30 04:14:55
  • OfStack

The ubound function method in JavaScript returns the maximum index value used in the specified dimension of VBArray. Usage:


safeArray.ubound(dimension)

SafeArray is a mandatory option. Is a VBArray object.
Dimensions are optional. To find the dimension of the VBArray whose index is bounded above. If ignored, ubound handles the parameter as a 1.

If the VBArray is empty, the ubound method returns undefined. If dim is greater than the dimension of VBArray or is negative, this method produces an "index out of bounds" error.

The sample

The following example consists of three parts. The first part is the VBScript code to create a Visual Basic security array. The second part is the JScript code, which determines the dimensions of the safe array and the upper bound of each dimension. Both parts are in the HTML page. HEAD> Part. The third part is located in < BODY> Part of the JScript code 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
         k = k + 1
      Next
   Next
   CreateVBArray = a
End Function
-->
</SCRIPT> <SCRIPT LANGUAGE="JScript">
<!--
function VBArrayTest(vba)
{
   var i, s;
   var a = new VBArray(vba);
   for (i = 1; i <= a.dimensions(); i++)
   {
      s = "The upper bound of dimension ";
      s += i + " is ";
      s += a.ubound(i)+ ".
";
      return(s);
   }
}
-->
</SCRIPT>
</HEAD> <BODY>
<SCRIPT language="jscript">
   document.write(VBArrayTest(CreateVBArray()));
</SCRIPT>
</BODY>


Related articles: