UBOUND
The UBOUND function returns the largest valid index (upper bound) of an array dimension.
Syntax
- result% = UBOUND(arrayName[, dimension%])
- result% = UBOUND(parentArray(index).subordinateNestedArray[, dimension%])
Description
- arrayName specifies the name of the array.
- dimension% specifies the dimension number, starting with 1 for the first dimension.
- If omitted, dimension% is assumed to be 1.
- If dimension% is less than 1 or is greater than the number of dimensions, a subscript out of range error occurs.
- UBOUND and LBOUND are used to determine the range of valid indexes of an array.
Notes on the second Syntax
QB64-PE v4.5.0 extends UBOUND support for arrays nested inside TYPE definitions. Besides the traditional use on ordinary arrays, UBOUND may now also be used on an individual nested array member, or on a parent array/variable containing such members.
Availability
-
all
-
all
-
yes
-
yes
-
yes
- Since arrays in TYPEs were implemented in QB64-PE v4.5.0, this statement was adapted to properly handle it (see Example 2).
Examples
- Example 1
- The classical use on ordinary arrays.
DIM myArray(5) AS INTEGER DIM myOtherArray(1 TO 2, 3 TO 4) AS INTEGER PRINT UBOUND(myArray) PRINT UBOUND(myOtherArray, 2) |
5 4 |
- Example 2
- The new usage on subordinary and nested arrays.
TYPE test a(1 to 50) AS LONG END TYPE DIM Parent(1) AS test PRINT UBOUND(Parent) PRINT UBOUND(Parent(0).a) |
1 50 |
See also