UBound: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
No edit summary
(Add javascript snippet)
Line 5: Line 5:
UBound returns a long value specifying the largest available subscript in the specified dimension of a given array. The required parameter, ''array'', is any array variable. The optional parameter, ''dimension'', specifies which dimension's upper bound is returned, beginning with the default, 1.  If the array is empty, -1 is returned. (For Android 2.1, use array.length instead.)
UBound returns a long value specifying the largest available subscript in the specified dimension of a given array. The required parameter, ''array'', is any array variable. The optional parameter, ''dimension'', specifies which dimension's upper bound is returned, beginning with the default, 1.  If the array is empty, -1 is returned. (For Android 2.1, use array.length instead.)


== Example ==
== Example (Basic) ==


<pre>
<pre>
Rem UBound Example
Rem UBound Example
'UBound returns upper bound of array dimension
'UBound returns upper bound of array dimension
Dim Other, Children(3), Parents(3, 1)
Dim Other, Children(3), Parents(3, 1)
Other = Array("Damien", "Pip", "Wendy")
Other = Array("Damien", "Pip", "Wendy")
Line 19: Line 20:
</pre>
</pre>


== Example (JavaScript) ==
<pre>
// UBound Example
/* Length returns upper bound of array dimension + 1 */
var Other, Children=new Array(3), Parents=new Array(3,1);
Other= new Array("Damien" , "Pip" , "Wendy");
Parents[3]=''; //need to assign variable to use length on multidim array
document.write("'Other' Upper Bounds: " + ((Other.length)-1).toString() + "<br>");
document.write("'Children' Upper Bounds: " + ((Children.length)-1).toString() + "<br>");
document.write("'Parents' Upper Bounds: " + ((Parents.length)-1).toString() + "<br>");
</pre>
== Output ==
== Output ==



Revision as of 03:55, 19 May 2013

UBound(array[, dimension])

Description

UBound returns a long value specifying the largest available subscript in the specified dimension of a given array. The required parameter, array, is any array variable. The optional parameter, dimension, specifies which dimension's upper bound is returned, beginning with the default, 1. If the array is empty, -1 is returned. (For Android 2.1, use array.length instead.)

Example (Basic)

Rem UBound Example
'UBound returns upper bound of array dimension

Dim Other, Children(3), Parents(3, 1)
Other = Array("Damien", "Pip", "Wendy")
Print "'Other' Upper Bound:", Ubound(Other)
Print "'Children' Upper Bound:", _
       UBound(Children, 1)
Print "'Parents' Upper Bounds:", _
       UBound(Parents), UBound(Parents, 2)

Example (JavaScript)

// UBound Example
/* Length returns upper bound of array dimension + 1 */

var Other, Children=new Array(3), Parents=new Array(3,1);
Other= new Array("Damien" , "Pip" , "Wendy");
Parents[3]=''; //need to assign variable to use length on multidim array
document.write("'Other' Upper Bounds: " + ((Other.length)-1).toString() + "<br>");
document.write("'Children' Upper Bounds: " + ((Children.length)-1).toString() + "<br>");
document.write("'Parents' Upper Bounds: " + ((Parents.length)-1).toString() + "<br>");

Output

'Other' Upper Bound:2
'Children' Upper Bound:    3
'Parents' Upper Bounds:    3      1

Related Items

Array, Dim, LBound, ReDim