3.1 Attributes and Directives

Directives are non-executable statements that influence the semantics of the module they're located in, or the member they're referring to.

These include Option statements:

Directive Description
Option Explicit Implicit declarations become compile-time errors
Option Base Determines the base (0 or 1) of implicitly-sized arrays
Option Compare Determines the comparison mode (Text or Binary, or a host-defined token to dynamically configure this value) for string comparisons
Option Private Module Determines the accessibility of a module

Directives also include Def<Type> implicit definition statements:

Directive Description
DefBool Configures implicit definitions for VBBooleanType
DefByte Configures implicit definitions for VBByteType
DefInt Configures implicit definitions for VBIntegerType
DefLng Configures implicit definitions for VBLongType
DefLngLng Configures implicit definitions for VBLongLongType in 64-bit environments
DefLngPtr Configures implicit definitions for VBLongPtrType_x86 (32-bit) or VBLongPtrType_x86 (64-bit)
DefCur Configures implicit definitions for VBCurrencyType
DefSng Configures implicit definitions for VBSingleType
DefDbl Configures implicit definitions for VBDoubleType
DefDate Configures implicit definitions for VBDateType
DefStr Configures implicit definitions for VBStringType
DefObj Configures implicit definitions for VBObjectType
DefVar Configures implicit definitions for VBVariantType

Other directives include Implements and Attribute statements:

Directive Description
Implements Specifies that the (class) module implements an interface class.
Attribute Specifies flags and modifiers that alter the semantics of a module or member.

3.1.1 Attributes

Note

MS-VBAL 5.2.3 Module Declaration: 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 interpretation of the RDCore platform is that this section of the MS-VBAL specification:

  • Relates specifically to the MS-VBA implementation and the Microsoft VBIDE, which is out of scope for RD-VBA;
  • Affirms Attribute statements as valid VBA language constructs;

Therefore:

  • Attribute statements are valid RD-VBA language constructs;
  • Whether a RD-VBA client / editor displays Attribute statements and/or allows their composition within the editor, is implementation-dependent.
  • Compilation in RD-VBA is the responsibility of the environment host, i.e. the rdc.exe console client - specifically, it is normally NOT a concern for any other client or IDE.

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

Tip

MS-VBA attribute semantics are severely truncated; RD-VBA has no reason not to honor their semantics accordingly with their original VB6 intent.

3.1.1.1 VB_Name

If present, the value of a VB_Name attribute determines the Name of the symbol for that module.

If omitted, the environment host may inject one with a value that matches the file name of the module, stripped of any empty spaces or other characters that would be illegal in a valid identifier name:

  • If there are no other attributes in the header, and no module name can be inferred from the file, the module is named Module followed by as many digits as necessary to make a unique module name, starting with Module1, then Module2, and so on until a unique name is determined.
  • If the header contains any other attributes, and no module name can be inferred from the file, the module is named Class followed by as many digits as necessary to make a unique module name, starting with 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, only if the 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 any editor-owned files modified by the editor.
Tip

See LSP 3.17 § WorkspaceEdit for more information about commanding client-side workspace edits from the language server. Note that the implementation must ensure that the LSP client does support the required capabilities for the requested edits.

3.1.1.2 VB_Creatable

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

The value of this attribute MUST be False in a VBA module, but may be True in a VB6 module, for RD-VBA clients that support the VB6 language, of which VBA is deemed a subset.

Tip

In practical terms, a not-creatable class module can only be directly instantiated within the project it is defined in (the enclosing project), but an instance of that class may be consumed by any referencing project if the module is exposed.

3.1.1.2 VB_Exposed

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

The value of this attribute is False for private modules, or True for public modules; a public module may be consumed by a referencing project, but whether a new instance of the module can be created outside of 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 this value is:

  • Private when both attribute values are False;
  • PublicNotCreatable given VB_Exposed=True but VB_Creatable=False;
  • PublicCreatable given VB_Exposed=True and VB_Creatable=True.
Note

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

3.1.1.3 VB_GlobalNameSpace

Determines whether a class module is exposed to the global namespace.

Note

This attribute is only meaningful in a library project.

3.1.1.4 VB_Customizable

This attribute 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 and may participate in persistence mechanisms used by designer hosts.

Note

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

VB6 sets it 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.

This attribute controls:

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

🎯 VB6 ActiveX designer features are out-of-scope for the RDCore language core.
🧩 VB6 ActiveX Designer features would be an very cool eventual platform extension though.

3.1.1.5 VB_PredeclaredId

Determines whether the environment host declares a global auto-object instance of the class with a predeclared ID, where the identifier name of the global auto-object has the same name as 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.

Tip

Setting an auto-object to Nothing destroys its internal state (semantic flags should identify whether a predeclared class module is stateful or not), but the object reference is immediately re-created as soon as it is being referred to, including within a Is Nothing reference check - that check is therefore statically constant (false).

3.1.1.6 VB_Description

This attribute holds a short documentation string that IDE tooling can then use to supply helpful tooltips.

Tip

Surfacing attributes does not necessarily make @Description annotations obsolete, because hiding Attribute directives may or may not be a capability that is supported by a LSP client.


⏮️ RD-VBAL §3.0 Syntax Tree | ⏮️ RD-VBAL §3.2 Literals