Table of Contents

3.1.1 Attributes

Note

MS-VBAL §5.2.3 Module Declarations: "Composition and compilation of Attribute statements is not permitted in the Microsoft Visual Basic for Applications editor, however, they are consumed and produced by Microsoft Visual Basic for Applications without error upon import and export and are therefore considered valid VBA language constructs."

The RDCore platform interprets this passage of the MS-VBAL specification as follows:

  • It relates specifically to the MS-VBA implementation and the Microsoft VBIDE. Both are out of scope for RD-VBA.
  • It affirms Attribute statements as valid VBA language constructs.

Therefore:

  • Attribute statements are valid RD-VBA language constructs.
  • Whether an RD-VBA client or editor displays Attribute statements is implementation-dependent.
  • Whether an RD-VBA client or editor allows the composition of Attribute statements within the editor is implementation-dependent.
  • Compilation in RD-VBA is the responsibility of the environment host, i.e. the rdc.exe console client (RD-VBAL §2.0 RD-VBA Computational Environment). Compilation is normally not a concern for any other RD-VBA client or IDE.

Attributes in the header section of a module determine the static semantics of that module.

MS-VBA attribute semantics are much reduced compared with their original VB6 intent. 🎯 RD-VBA honors attribute semantics according to their original VB6 intent, because nothing in RD-VBA calls for the MS-VBA reduction.

Section Attribute Determines
3.1.1.1 VB_Name The Name of the module's symbol.
3.1.1.2 VB_Creatable Whether a class module can be directly instantiated from a referencing project.
3.1.1.3 VB_Exposed Whether a class module is visible at all to a referencing project.
3.1.1.4 VB_GlobalNameSpace Whether a class module is exposed to the global namespace.
3.1.1.5 VB_Customizable Whether a class, method or property is customizable in designer hosts.
3.1.1.6 VB_PredeclaredId Whether the environment host declares a global auto-object instance of the class.
3.1.1.7 VB_Description A short documentation string for IDE tooltips.
3.1.1.8 VB_Extensible Whether a class module is an extensible ("document") module, whose members a host extends.

Members of a class can also carry a VB_UserMemId attribute, which can specify a number of flags that modify the behavior of the member. A class can have exactly one member with a VB_UserMemId attribute value of 0: that member is the class type's default member (RD-VBAL §2.4.2 Non-intrinsic Types).

3.1.1.1 VB_Name

If present, the value of a VB_Name attribute determines the Name of the symbol for that module. The Name of an RDCoreModule is always supplied by a VB_Name attribute: on a mismatch between RDCoreModule.Name and the value of the attribute, the attribute value always takes precedence (RD-VBAL §2.2.3 ProjectFile).

If VB_Name is omitted, the environment host may inject a VB_Name attribute whose value matches the file name of the module, stripped of spaces and of any other characters that would be illegal in a valid identifier name. If no module name can be inferred from the file, the module is named as follows:

The module header Module name
Contains no other attributes Module followed by as many digits as necessary to make a unique module name: Module1, then Module2, and so on until a unique name is determined.
Contains any other attributes Class followed by as many digits as necessary to make a unique module name: Class1, then Class2, and so on until a unique name is determined.

The environment host must inject any missing attributes before requesting the parsing of that module. It injects them only if the module file is not currently owned by any IDE or editor client.

If a module is missing a VB_Name attribute and is currently opened in an IDE or editor client, the language server may send a WorkspaceEdit notification, to have the editor-owned file modified by the editor. LSP 3.17 § WorkspaceEdit describes commanding client-side workspace edits from the language server.

An implementation that commands client-side workspace edits must ensure that the LSP client supports the capabilities required for the requested edits (RD-VBAL §2.0.2 Client/Server Capabilities).

3.1.1.2 VB_Creatable

VB_Creatable determines whether a class module can be directly instantiated using a New (or CreateObject) expression from a referencing project.

Module Value of VB_Creatable
A VBA module Must be False.
A VB6 module, for RD-VBA clients that support the VB6 language May be True.

VBA is deemed a subset of the VB6 language (RD-VBAL §2.0.1 Supported Languages).

A not-creatable class module can only be directly instantiated within the project it is defined in (the enclosing project). An instance of a not-creatable class may be consumed by any referencing project if the class module is exposed (§3.1.1.3).

3.1.1.3 VB_Exposed

VB_Exposed determines whether a class module is visible at all to a referencing project.

The value of VB_Exposed is False for private modules, and True for public modules. A public module may be consumed by a referencing project. Whether a new instance of a public module can be created outside the enclosing project that defines it depends on the value of its VB_Creatable attribute.

👉 Together, VB_Creatable and VB_Exposed determine the instancing mode of a class module (MS-VBAL §5.2.4.1.1 Class Accessibility and Instancing; RD-VBAL §5.2.4 Class Module Declarations):

VB_Exposed VB_Creatable Instancing mode
False False Private
True False PublicNotCreatable
True True PublicCreatable
Note

The PublicCreatable instancing mode is not a legal VBA configuration. RD-VBA implementations may allow it, with semantic flags issued, if the host environment is configured to allow building library projects.

3.1.1.4 VB_GlobalNameSpace

VB_GlobalNameSpace determines whether a class module is exposed to the global namespace.

Note

VB_GlobalNameSpace is only meaningful in a library project.

3.1.1.5 VB_Customizable

VB_Customizable marks a class, method, or property as customizable in host environments that support VB6 ActiveX Designers or VB6 Object Template. It indicates that the class or member:

  • supports design-time customization;
  • may participate in persistence mechanisms used by designer hosts.

A customizable class or member is allowed to appear in a .frx file or a property bag.

VB6 sets VB_Customizable automatically, depending on whether:

  • the class is Public or part of an ActiveX Project;
  • the member is eligible for design-time customization;
  • the member is persisted (serialized) in a property bag.

VB_Customizable controls:

  • how a component is described in a type library;
  • how a consuming COM host interprets those type library descriptions;
  • whether a designer tool can override or persist the member.

🎯 VB6 ActiveX designer features are out of scope for the RDCore language core (RD-VBAL §1.1.1 Platform Extensions).

3.1.1.6 VB_PredeclaredId

VB_PredeclaredId determines whether the environment host declares a global auto-object instance of the class with a predeclared ID. The identifier name of the global auto-object is the same as the name of the class module it is a predeclared instance of.

The "Id" refers to an internal unique semantic identifier given to every object in the host environment.

Static Semantics

The static semantics of VB_PredeclaredId (MS-VBAL §5.2.4.1.2 Default Instance Variables Static Semantics) are modeled.

A class module with VB_PredeclaredId = True has a VBPredeclaredInstanceSymbol (RD-VBAL §2.5.1 Runtime Entities). A VBPredeclaredInstanceSymbol is a global variable named after the class, whose declared type is that class.

The predeclared instance variable is created as if declared As New. It is therefore an automatic instantiation variable (SymbolProperties.AutoInstantiated, see SymbolProperties; MS-VBAL §2.5.1 Automatic Object Instantiation). For variables declared with an As New clause, see RD-VBAL §5.2.3 Module Declarations.

The class name binds as follows (RD-VBAL §2.3.1.3 Name Resolution):

Name Binding context Binds to
The name of a predeclared class Default (ISymbolResolver.ResolveValue) The class module's predeclared instance variable.
The name of a class that is not predeclared, used in an expression Default (ResolveValue) An undefined variable.
A class name Type (ResolveType: an As clause or New) The class.

For a predeclared class Widget, Widget.Size is therefore a member access on a variable of type Widget (RD-VBAL §5.6.12 Member Access Expressions).

Other than through its predeclared instance, a class module is never a name in the default binding context (ResolveValue). A class that is not predeclared has no default instance. Deferred class types cannot be presumed to have a default instance (RD-VBAL §2.4.4 Deferred Types).

It is invalid for the default instance variable to be the target of a Set assignment, whatever is assigned to it (MS-VBAL §5.2.4.1.2; RD-VBAL §5.4.3.9 Set Statement). For a predeclared class Widget:

Statement Outcome
Set Widget = New Widget Compile error VBC09304.
Set Widget = Nothing Compile error VBC09304.
Widget.Size = 3 Valid: it assigns a member of the object the default instance variable holds.
Set Widget = …, where a local variable or field is itself named Widget Valid: the local variable or field hides the default instance of class Widget, and is an ordinary Set target.
Note

Not implemented. The declaration-level validity of As New (MS-VBAL §5.2.3.1.4 Variable Type Declarations) is not modeled. See RD-VBAL §5.2.3 Module Declarations.

Runtime Semantics

Note

Not implemented. 🎯 The run-time behavior of the default instance described in this section (it is never Nothing; it is re-created on reference) is not modeled.

  • Setting an auto-object (a predeclared instance) to Nothing destroys its internal state.
  • Semantic flags should identify whether a predeclared class module is stateful or not (RD-VBAL §1.1.3 Core Semantic Flags).
  • An auto-object reference is re-created as soon as it is referred to, including within an Is Nothing reference check.
  • An Is Nothing check on an auto-object is therefore statically constant (False) (RD-VBAL §5.6.9.7 Is Operator).

3.1.1.7 VB_Description

VB_Description holds a short documentation string that IDE tooling can use to supply tooltips.

Surfacing attributes does not necessarily make @Description annotations obsolete (RD-VBAL §3.0.1.1 Comment Annotations Syntax): hiding Attribute directives may or may not be a capability that an LSP client supports.

3.1.1.8 VB_Extensible

VB_Extensible marks a class module as extensible: a module of the kind a host extends, such as a document module. Its value is the symbol's SymbolProperties.Extensible, read off the module by ModuleNodeExtensions.IsExtensible.

An extensible module cannot have an Implements directive (RD-VBAL §5.2.4.2): VBC09328.


⏮️ RD-VBAL §3.1 Attributes and Directives | ⏭️ RD-VBAL §3.2.0 Literal Expressions