Q(uick)BASIC Keyword: BASE

Quick View

BASE Keyword

OPTION BASE declares the default lower bound for array subscripts

Worth knowing

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

Syntax
  • OPTION BASE {0 | 1}
Description/Parameter(s)

The DIM statement TO clause provides a better way to set the lower bound of an array subscript.

Syntax
  • OPTION BASE n
Description/Parameter(s)

The OPTION BASE statement is never required. It is used to change the default lower bound for array subscripts.

The value of n must be either 0 or 1. The default base is 0. If the following statement

  • OPTION BASE 1

is executed, the lowest value an array subscript can have is 1.

Note:> DIM statement provides an easier, more flexible way to control the range of an array's subscripts. If the lower bound of an array subscript is not explicitly set, then OPTION BASE can be used to change the default lower bound to 1.

The OPTION BASE statement can be used only once in a module (source file) and can only appear in the module-level code. An OPTION BASE statement must be used before any arrays are dimensioned.

Chained programs may have an OPTION BASE statement if no arrays are passed in COMMON between them or if the specified base is identical in the chained programs. The chained-to program inherits the OPTION BASE value of the chaining program if OPTION BASE is omitted in the latter.

Example

This example shows the use of OPTION BASE to override the default base array subscript value of 0. Subscripts in array A range from 1 to 20 rather than 0 to 19.

CLS ' Clear screen OPTION BASE 1 DIM A(20) PRINT "The base subscript in array A is"; LBOUND(A) PRINT "The upper bound subscript in array A is"; UBOUND(A)

Sample Output:

The base subscript in array A is 1 The upper bound subscript in array A is 20
Syntax
  • OPTION BASE n%
Description/Parameter(s)

The value of n% must be either 0 or 1. The default base is 0. If the following statement is encountered, the default lowest value of an array subscript is 1:

OPTION BASE 1

Usage Notes

  • The OPTION BASE statement is never required. It is used to change the default lower bound for array subscripts.
  • The OPTION BASE statement can be used only once in a module (source file) and can only appear in the module-level code. An OPTION BASE statement must be used before you can declare the dimensions for any arrays.
  • Chained programs can have an OPTION BASE statement if no arrays are passed in COMMON between them in a COMMON block, or if the specified base is identical in the chained programs. The chained-to program inherits the OPTION BASE value of the chaining program if OPTION BASE is omitted in the latter.

Important

  • The TO clause in the DIM statement provides an easier, more flexible way to control the range of an array's subscripts. If the lower bound of an array subscript is not explicitly set, OPTION BASE can be used to change the default lower bound to 1.
Example

This example uses the OPTION BASE statement to override the default base array subscript value of 0. Subscripts in array A range from 1 to 20 rather than 0 to 20.

CLS 'Clear screen. OPTION BASE 1 DIM A(20) PRINT "The base subscript in array A is"; LBOUND(A) PRINT "The upper bound subscript in array A is"; UBOUND(A)

Sample Output:

The base subscript in array A is 1 The upper bound subscript in array A is 20