Skip to main content

Option Base statement

Table of contents
  1. Syntax
  2. Remarks
  3. Examples

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

Syntax

Option Base { 0 | 1 }

Remarks

Because the default base is 0, the Option Base statement is never required. If used, the statement must appear in a module before any procedures. Option Base can appear only once in a module and must precede array declarations that include dimensions.

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

Examples

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. 
 
Dim Lower 
Dim MyArray(20), TwoDArray(3, 4) ' Declare array variables. 
Dim ZeroArray(0 To 5) ' Override default base subscript. 
' Use LBound function to test lower bounds of arrays. 
Lower = LBound(MyArray) ' Returns 1. 
Lower = LBound(TwoDArray, 2) ' Returns 1. 
Lower = LBound(ZeroArray) ' Returns 0.

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>