UBOUND function

Purpose

Return the largest possible subscript (boundary) for an array's specified dimension.

Syntax

y = UBOUND(array [(dimension)])

y = UBOUND(array, dimension)

Remarks

array is the array of interest.  dimension is an integer-class value or expression from 1 up to the number of dimensions in array; it specifies which dimension's upper bound value will be returned.  If you omit dimension, it defaults to 1 (the first dimension).  To find the lower bound of an array's dimension, use the LBOUND function.  Use LBOUND and UBOUND together to determine an array's size.  UBOUND of an undimensioned array returns -1, so that UBOUND(array) - LBOUND(array) + 1  yields zero (0) for such an array.

Restrictions

UBOUND cannot be used on arrays within User-Defined Types.

See also

ARRAYATTR, DIM, LBOUND, REDIM

Example

' Dimension an array with lower and upper bounds

DIM MyArray%(1900 TO 2000,5 TO 10)

 

' print out the values of the array

Message$ = "The array's first dimension is from" + _

           STR$(LBOUND(MyArray%(1))) + "to" + _

           STR$(UBOUND(MyArray%(1)))

Message$ = "The array's second dimension is from" + _

           STR$(LBOUND(MyArray%(2))) + "to" + _

           STR$(UBOUND(MyArray%(2)))

Result

The array's first dimension is from 1900 to 2000

The array's second dimension is from 5 to 10