Option Base Statement

 

Option Base number

 

Declares the default lower bound for array subscripts.

 

The Option Base statement is never required.  If used, it can appear only once in a module, it can occur only in the Declarations section, and must be used before you declare the dimensions of any arrays.

 

The value of number must be either 0 or 1.  The default base is 0.

 

The To clause in the Dim, Global, 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 example uses the Option Base statement to override the default base array subscript value of 0.

 

Related Topics:  Dim, Global and Lbound Statements

 

Example :

 

Option Base 1 ' Module level statement.

Sub Main

   Dim A(), Msg, NL ' Declare variables.

   NL = Chr(10)  ' Define newline.

   ReDim A(20)   ' Create an array.

   Msg = "The lower bound of the A array is " & LBound(A) & "."

   Msg = Msg & NL & "The upper bound is " & UBound(A) & "."

   MsgBox Msg ' Display message.

End Sub