Q(uick)BASIC Function: LBOUND

Quick View

LBOUND

A memory function that returns the lower bound (smallest available subscript) for the indicated dimension of an array

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Syntax
  • LBOUND(array[,dimension%])
  • UBOUND(array[,dimension%])
Description/Parameter(s)
array The name of the array.
dimension% Indicates the array dimension whose lower or upper bound is returned. Use 1 for the first dimension, 2 for the second dimension, etc. The default is 1.
Example
DIM a%(1 TO 3, 2 TO 7) PRINT LBOUND(a%, 1), UBOUND(a%, 2)

See also:

Syntax
  • LBOUND(array[,dimension])
Description/Parameter(s)

The LBOUND function is used with the UBOUND function to determine the size of an array.

Argument Description
array The name of the array being dimensioned
dimension An integer ranging from 1 to the number of dimensions in array: indicates which dimension's lower bound is returned

For an array dimensioned as follows, LBOUND returns the values listed below:

  • DIM A(1 TO 100, 0 TO 50, -3 TO 4)
Invocation Value Returned
LBOUND(A,1)  1
LBOUND(A,2)  0
LBOUND(A,3) -3

The default lower bound for any dimension is either 0 or 1, depending on the setting of the OPTION BASE statement. If OPTION BASE is 0, the default lower bound is 0, and if OPTION BASE is 1, the default lower bound is 1.

Arrays dimensioned using the TO clause in the DIM statement may have any integer value as a lower bound.

You may use the shortened syntax LBOUND(array) for one-dimensional arrays, since the default value for dimension is 1. Use the UBOUND function to find the upper limit of an array dimension.

Example

See the UBOUND function programming example , which uses both the LBOUND and UBOUND functions.

See also:

Syntax
  • LBOUND(array[,dimension%])
Description/Parameter(s)

Usage Notes

  • The LBOUND function is used with the UBOUND function to determine the size of an array.
  • LBOUND returns the values listed below for an array with the following dimensions:

  • DIM A(1 TO 100, 0 TO 3, -3 TO 4)
Invocation Value Returned
LBOUND(A,1)  1
LBOUND(A,2)  0
LBOUND(A,3) -3
  • The default lower bound for any dimension is either 0 or 1, depending on the setting of the OPTION BASE statement. If OPTION BASE is 0, the default lower bound is 0, and if OPTION BASE is 1, the default lower bound is 1.
  • Arrays dimensioned using the TO clause in the DIM statement can have any integer value as a lower bound.
  • You can use the shortened syntax LBOUND(array) for one-dimensional arrays, because the default value for dimension% is 1.
Example

This example uses the LBOUND and UBOUND functions in a SUB procedure to determine the size of an array passed to the procedure by a calling program.

DECLARE SUB PRNTMAT (A!()) DIM A(0 TO 3, 0 TO 3) FOR I% = 0 TO 3 FOR J% = 0 TO 3 A(I%, J%) = I% + J% NEXT J% NEXT I% CALL PRNTMAT(A()) END SUB PRNTMAT (A()) STATIC FOR I% = LBOUND(A, 1) TO UBOUND(A, 1) FOR J% = LBOUND(A, 2) TO UBOUND(A, 2) PRINT A(I%, J%); " "; NEXT J% PRINT : PRINT NEXT I% END SUB