Option Base statement
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.
Note
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 base of an array created with the ParamArray keyword is zero; Option Base does not affect ParamArray (or the Array function, when qualified with the name of its type library, for example VBA.Array).
The Option Base statement only affects the lower bound of arrays in the module where the statement is located.
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.
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.
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기