5.2.3 Module Declarations
Note
This section describes the implementation of MS-VBAL §5.2.3 Module Declarations.
A standard module's non-Private members (an explicit Public / Global / Friend, or an implicit
procedure-like member) are also declared in the project scope. Because of this, a sibling module resolves them
without qualification (RD-VBAL §2.3.1.3 Name Resolution).
5.2.3.1 Module Variable Declaration Lists
Note
This section describes the implementation of MS-VBAL §5.2.3.1 Module Variable Declaration Lists.
👉 When an array declaration specifies no item type, the declared item type of the array is Variant
(RD-VBAL §2.4.1 Intrinsic Types;
RD-VBAL §2.5.2.1.2 Array Values).
5.2.3.1.1 Variable Declarations
Note
This section describes the implementation of MS-VBAL §5.2.3.1.1 Variable Declarations.
Any variable declared with an As New clause is an automatic instantiation variable
(MS-VBAL §2.5.1 Automatic Object Instantiation).
Its symbol carries the AutoInstantiated property of
SymbolProperties
(RD-VBAL §2.5.1 Runtime Entities;
RD-VBAL §3.1.1 Attributes).
The default instance variable of a predeclared class is created as if declared As New
(RD-VBAL §5.2.4 Class Module Declarations, §5.2.4.1.2).
5.2.3.1.2 WithEvents Variable Declarations
This section corresponds to MS-VBAL §5.2.3.1.2 WithEvents Variable Declarations.
A WithEvents variable is a variable of a class module whose declared type is a class with events. The symbol of such a variable has the WithEvents property (SymbolProperties.WithEvents), which the language server sets from the WithEvents keyword and sends to the environment host in its descriptor (SymbolDescriptor.IsWithEvents). The procedures of the module named VariableName_EventName handle that event of the object the variable holds (RD-VBAL §5.3.1.8).
Assigning the variable with Set attaches its handlers to the object it is given, and detaches them from the object it held (RD-VBAL §5.4.3.9).
The declared type must be a specific class with at least one event, and must not be the class of the module containing the declaration; ClassModuleEventSemantics reports one that is not as VBC09324. A type that is not resolved is not reported.
5.2.3.1.3 Array Dimensions and Bounds
Note
This section describes the implementation of MS-VBAL §5.2.3.1.3 Array Dimensions and Bounds.
The declaration pass binds the declared type of an array symbol from the array-dim clause alone, before any bound is evaluated (RD-VBAL §2.4.1 Intrinsic Types).
An array declaration creates an array value of the appropriate array type in the scope of the declaration (RD-VBAL §2.5.2.1.2 Array Values):
| Array-dim clause | Example | Declared type | Array value created |
|---|---|---|---|
| One or more bounds (dimension specifications) | Dim g(1 To 3, 0 To 4) As Long |
VBFixedSizeArrayType | VBFixedSizeArrayValue |
An empty () clause |
Dim b() As Long |
VBResizableArrayType | VBResizableArrayValue |
A trailing () on the As clause |
Dim b As Long() |
VBResizableArrayType |
VBResizableArrayValue |
An empty () clause, or a trailing () on the As clause, with a Byte item type |
Dim b() As Byte |
VBResizableByteArrayType | VBResizableByteArrayValue |
An array has up to 60 dimensions.
Resolving an omitted lower bound against Option Base is specified in
RD-VBAL §5.2.1 Option Directives (§5.2.1.2).
5.2.3.1.4 Variable Type Declarations
Note
This section describes the implementation of MS-VBAL §5.2.3.1.4 Variable Type Declarations.
A declared type name binds in the type binding context. With the
CompositeSymbolResolver, a module's As SomeType
binds to a sibling module's Type or Enum, or to a class, not only to a reserved data-type name
(RD-VBAL §2.3.1.3 Name Resolution).
MS-VBAL §5.2.3.1.4: the type specified in an As New clause must be a named class, and must be creatable unless
it is declared in the same project.
Note
Not implemented. The declaration-level validity of As New (MS-VBAL §5.2.3.1.4) is not modeled.
5.2.3.1.5 Implicit Type Determination
This section corresponds to MS-VBAL §5.2.3.1.5 Implicit Type Determination.
Note
Reserved. This section has no content yet.
5.2.3.2 Const Declarations
This section corresponds to MS-VBAL §5.2.3.2 Const Declarations.
Note
Reserved. This section has no content yet.
5.2.3.3 User Defined Type Declarations
Note
This section describes the implementation of MS-VBAL §5.2.3.3 User Defined Type Declarations.
MS-VBAL §5.2.3.3 uses the same accessibility wording as MS-VBAL §5.2.3.4 Enum Declarations: a user-defined type is accessible within the enclosing project, or within the enclosing module.
A public user-defined type declared in a class module reaches the project scope. A class module's other members need an instance to be reached through, but a declared type needs none (RD-VBAL §5.2.3.4 Enum Declarations).
The data type of a UDT value is defined by the UDT declaration of its declared type (RD-VBAL §2.5.2.1.3 User-Defined Type (UDT) Values).
5.2.3.4 Enum Declarations
Note
This section describes the implementation of MS-VBAL §5.2.3.4 Enum Declarations.
MS-VBAL §5.2.3.4 states that "the Enum type and its Enum members are accessible within the enclosing project" / "within the enclosing module".
An Enum's members are lexically scoped like the Enum type itself: accessible within the enclosing project, or
within the enclosing module.
| Aspect | Enum member |
|---|---|
| Access modifier | An Enum member has no access modifier of its own. |
| Visibility | An Enum member takes its visibility from its Enum's own access modifier. |
| Symbol parent | An enum constant (Enum member) symbol parents to its Enum rather than to a scope. |
| Scope placement | ScopeTreeBuilder resolves an Enum member's scope placement through its Enum (RD-VBAL §2.3.1.3 Name Resolution). |
👉 Because Enum members are placed through their Enum, an Enum member such as vbSunday is a name on its own,
resolvable without qualification.
A public Enum declared in a class module reaches the project scope. A class module's other members need an
instance to be reached through, but a declared type (an Enum or a user-defined type) needs none.
5.2.3.5 External Procedure Declaration
This section corresponds to MS-VBAL §5.2.3.5 External Procedure Declaration.
Note
Reserved. This section has no content yet.
5.2.3.6 Circular Module Dependencies
This section corresponds to MS-VBAL §5.2.3.6 Circular Module Dependencies.
Note
Reserved. This section has no content yet.
⏮️ RD-VBAL §5.2.2 Implicit Definition Directives | ⏭️ RD-VBAL §5.2.4 Class Module Declarations