5.2.1 Option Directives
Note
This section describes the implementation of MS-VBAL §5.2.1 Option Directives.
Directives include the Option statements
(RD-VBAL §3.1 Attributes and Directives):
| Directive | Description |
|---|---|
Option Compare |
Determines the comparison mode for string comparisons (§5.2.1.1). |
Option Base |
Determines the base (0 or 1) of implicitly-sized arrays (§5.2.1.2). |
Option Explicit |
Implicit declarations become compile-time errors (§5.2.1.3). |
Option Private Module |
Determines the accessibility of a module (§5.2.1.4). |
A module's LexicalScope carries its ModuleDirectives (RD-VBAL §2.3.1.3 Name Resolution):
| Member | Description |
|---|---|
Explicit |
Whether the module declares Option Explicit. |
Compare |
The module's Option Compare mode. |
Strict |
Reserved for RD-VBA's '@OptionStrict annotation. No symbol provider sets it, so it is always false, and nothing reads it. |
ModuleDirectives is reachable from any scope nested under the module, via
LexicalScope.EnclosingModuleDirectives().
A class module's directives govern its code as a standard module's do: Option Explicit makes an undeclared name in
the class a compile error, which keeps the class from loading; Option Compare is how its relational operators
compare String values, whatever the mode of the module that calls it; and Option Base is the lower bound its
arrays take when they state none. The host finds the module by its name among the session's modules
(ISessionSymbols.TryGetModule), both when it
gives the module's symbol its directives and when a new activation takes its frame's directives from the module its
procedure is declared in. This is a lookup of the modules themselves, not a binding of the name: in code, the name of a
class with a default instance is that instance, and a class module's name is no value at all
(RD-VBAL §5.6.4 Expression Binding Contexts). The lookup ignores
case, and a module of the project comes before a library's of the same name.
5.2.1.1 Option Compare Directive
Note
This section describes the implementation of MS-VBAL §5.2.1.1 Option Compare Directive.
The Option Compare directive determines the comparison mode for string comparisons: Text or Binary. The
comparison mode may instead be a host-defined token, which dynamically configures the comparison mode.
5.2.1.2 Option Base Directive
Note
This section describes the implementation of MS-VBAL §5.2.1.2 Option Base Directive.
The Option Base directive determines the base (0 or 1) of implicitly-sized arrays.
The lower bound of an uninitialized array value depends on the value of the Option Base directive
(RD-VBAL §2.5.2.1.2 Array Values):
Option Base |
Lower bound |
|---|---|
| Not specified (the default) | 0 |
Option Base 1 |
1 |
Resolving an omitted array lower bound against Option Base is the concern of the semantic pass that materializes
the array value, not of the declaration pass
(RD-VBAL §2.4.1 Intrinsic Types).
Important
MS-VBAL says the directive sets the default lower bound "of all array dimensions" of the module, but MS-VBA does not apply it to an
array field of a user-defined type, which starts at 0 regardless; RD-VBA does what MS-VBA does. Under Option Base 1, a field
Values(4) As Long of a Type is 0 To 4, and a Dim Values(4) As Long beside it is 1 To 4.
5.2.1.3 Option Explicit Directive
Note
This section describes the implementation of MS-VBAL §5.2.1.3 Option Explicit Directive.
Under the Option Explicit directive, implicit declarations become compile-time errors.
Whether the enclosing module declares Option Explicit is the module-level fact a static semantics rule needs
(RD-VBAL §5.0 Semantics, §5.0.1). The static-semantics layer consumes
ModuleDirectives to decide what an unresolved simple name is
(RD-VBAL §5.6.10 Simple Name Expressions):
Module declares Option Explicit |
An unresolved simple name is |
|---|---|
| No | A deferred VBUnknownType. |
| Yes | A VBC09302 Variable not defined compile-time error: an Error carrying VariableNotDefined (VBCompileErrorId). |
An implicit declaration by an unqualified ReDim target is legal under Option Explicit
(RD-VBAL §5.4.3.3 ReDim Statement).
5.2.1.4 Option Private Directive
Note
This section describes the implementation of MS-VBAL §5.2.1.4 Option Private Directive.
The Option Private Module directive determines the accessibility of a module.