The ubound function in JavaScript uses the example, javascriptubound
In JavaScript, The ubound function returns the maximum index value used in the specified dimension of VBArray. Usage:
Copy codeThe Code is as follows:
SafeArray. ubound (dimension)
SafeArray is required. Is a VBArray object.
Dimension is optional. You need to know the dimension of the VBArray on the upper bound of the index. If this parameter is ignored, ubound treats this parameter as 1.
If VBArray is empty, the ubound method returns undefined. If dim is greater than the dimension of VBArray or is a negative number, this method will generate a "subscript out of bounds" error.
Example
The following example consists of three parts. The first part is the VBScript code used to create a Visual Basic security array. The second part is the JScript code to determine the dimension of the security array and the upper bound of each dimension. Both parts are placed in the <HEAD> section on the HTML page. The third part is the JScript code in the <BODY> section, which is used to run the other two parts.
Copy codeThe Code is as follows:
<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 =
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>
VB does not know how to use ubound Functions
UBound Function
Returns a Long data with the maximum subscript that can be used for the specified array dimension.
Syntax
UBound (arrayname [, dimension])
The UBound function syntax includes the following parts:
Required. The name of the array variable, which complies with the naming conventions of standard variables.
Optional; Variant (Long ). Specifies the upper bound of the returned dimension. 1 indicates the first dimension, 2 indicates the second dimension, and so on. If dimension is omitted, it is regarded as 1.
Therefore, your ubound (A, 1) is the maximum subscript that returns the I dimension.
It is generally used in dynamic arrays. the maximum static subscript is already known in definition.
Problems in the application of Function array and ubound
Returns a Long data with the minimum subscript that can be used for the specified array dimension.
Syntax
LBound (arrayname [, dimension])
The syntax of the LBound function includes the following parts:
Partial description
Required. The name of the array variable, which follows the standard variable naming conventions.
Optional; Variant (Long ). Specifies the lower bound of the returned dimension. 1 indicates the first dimension, 2 indicates the second dimension, and so on. If dimension is omitted, it is regarded as 1.
Description
The LBound function is used with the UBound function to determine the size of an array. UBound is used to determine the upper bound of a one-dimensional array.
For an array with the following dimensions, the return value of LBound is shown in the following table:
Dim A (1 To 100, 0 To 3,-3 To 4)
Statement Return Value
LBound (A, 1) 1
LBound (A, 2) 0
LBound (A, 3)-3
The default lower bound of all dimensions is 0 or 1, depending on the Option Base statement. The lower bound of the Array created using the Array Function is 0; it is not affected by Option Base.
For arrays that use the To clause To set dimensions in Dim, Private, Public, ReDim, or Static statements can use any integer as the lower limit.
Returns a Long data with the maximum subscript that can be used for the specified array dimension.
Syntax
UBound (arrayname [, dimension])
The UBound function syntax includes the following parts:
Partial description
Required. The name of the array variable, which complies with the naming conventions of standard variables.
Optional; Variant (Long ). Specifies the upper bound of the returned dimension. 1 indicates the first dimension, 2 indicates the second dimension, and so on. If dimension is omitted, it is regarded as 1.
Description
The UBound function is used with the LBound function to determine the size of an array. LBound is used to determine the upper bound of a one-dimensional array.
For arrays with the following dimensions, the returned values of UBound are shown in the table below:
Dim A (1 To 100, 0 To 3,-3 To 4)
Statement Return Value
UBound (A, 1) 100
UBound (A, 2) 3
UBound (A, 3) 4
LBound function example
This example uses the LBound function to return the minimum available subscript of the specified dimension of the array. You can use the Option Base statement to replace the default value 0 of the array.
Dim Lower
Dim MyArray (1 To 10, 5 To 15, 10 To 20) 'declares the array variable.
Dim AnyArray (10)
Lower = Lbound (MyArray, 1) 'returns 1.
Lower = Lbound (MyArray, 3) 'returns 10.
Lower = Lbound (AnyArray) 'returns 0 or 1, depending on
'Option Base settings.
UBound function example
This example uses the UBound function to determine the maximum available subscript of the specified dimension of the array.
Dim Upper
Dim MyArray (1 To 10, 5 To 15, 10 To 20) 'declares the array variable.
Dim AnyArray (10)
Upper = UBound (MyArray, 1) 'returns 10.
Upper = UBound (MyArray, 3) 'returns 20.
Upper =... the remaining full text>