Option Base Statement

See Also6YRP0J9                 ExampleCYRX3GE>Low

Declares the default lower bound for arrayYPCGZO subscripts.

Syntax

Option Base number

Remarks

The Option Base statement is never required.  If used, it can appear only once in a form or module, 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 Option Base statement has no effect on arrays within user-defined types.  However, use caution, as this will not be true in future versions of Visual Basic.  The lower bound for all such arrays is always 0.

 

Tip   The To clause in the Dim, Global, 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.

 


See Also

Dim StatementLANDIM

Global StatementTDN897

LBound FunctionY0NKEZ

ReDim StatementQ1CGU1

Static StatementCC4JTI


Option Base Statement Example

The example uses the Option Base statement to override the default base array subscript value of 0.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

Option Base 1                ' Module level statement.
Sub Form_Click ()
  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