Option Base Statement

Description

Used at module level to declare the default lower bound for array subscripts.

Syntax

Option Base {0 | 1}

Remarks

If used, the Option Base statement must appear in a module before any statements that declare variables or define constants.

Since the default base is 0, the Option Base statement is never required. However, if used, it can appear only once in a module and must precede array declarations that include dimensions.

Tip The To clause in the Dim, Private, Public, ReDim, and Static statements provides a more flexible way to control the range of an array’s subscripts. However, if you don’t explicitly set the lower bound with a To clause, you can use Option Base to change the default lower bound to 1.

The Option Base statement only affects the lower bound of arrays in the module where the statement is located.

See Also

Dim Statement, LBound Function, Option Compare Statement, Option Explicit Statement, Option Private Statement, Private Statement, Public Statement, ReDim Statement, Static Statement.

Example

This example uses the Option Base statement to override the default base array subscript value of 0. The LBound function returns the smallest available subscript for the indicated dimension of an array. The Option Base statement is used at the module level only.


Option Base 1                    ' Set default array subscripts to 1.MyArray(20), TwoDArray(3, 4)    ' Declare array variables.ZeroArray(0 To 5)            ' Override default base subscript.
' Use LBound function to test lower bounds of arrays.= LBound(MyArray)            ' Returns 1.= LBound(TwoDArray, 2)        ' Returns 1.= LBound(ZeroArray)        ' Returns 0.