2.4.2 Non-intrinsic Types
Non-intrinsic types are additional RD-VBA internal data types. They are not exposed to, or directly usable in, workspace source code. They complete the model of the system.
The non-intrinsic types are:
| Type | Section |
|---|---|
| VBStdModuleType | §2.4.2.1 |
| VBClassType | §2.4.2.2 |
| VBCollectionType | §2.4.2.3 |
| VBEnumType | |
| VBProjectType | §2.4.2.4 |
| VBUnknownType | §2.4.2.5 |
| VBVoidType | §2.4.2.6 |
2.4.2.1 VBStdModuleType
VBStdModuleType represents a standard module. A standard module is functionally equivalent to a managed static class.
A standard module is defined by workspace source code, or imported from a referenced library.
2.4.2.2 VBClassType
VBClassType represents an object type defined by workspace source code in a class module.
VBClassType implements IVBMemberOwnerType. Through this interface, it exposes an immutable array of VBTypeMemberSymbol, where each element describes a member of the class type.
2.4.2.2.1 SuperTypes
Class modules defined in workspace source code have no means to inherit another class module, in the Object-Oriented Programming sense of inheritance; see also RD-VBAL §5.2.4 Class Module Declarations.
All VBA classes nevertheless implicitly implement a Class interface that exposes the Initialize and Terminate events:
Class member |
Raised upon |
|---|---|
Initialize |
Instantiation of an instance (object) of a given class type |
Terminate |
Destruction of an instance (object) of a given class type |
The class has no Implements directive for it, but the interface is included in the SuperTypes array like any interface the class implements, its members having an implementation of their own (DefaultImplementation); it cannot be referred to by name. See RD-VBAL §5.3.1.10 Lifecycle Handler Declarations.
If a class module specifies any Implements directives (MS-VBAL §5.2.4.2 Implements Directive), the interfaces specified by those directives are included in the class type's SuperTypes array.
2.4.2.2.1.1 Extensible ("Document") Modules
Extensible class modules (also called "document" modules) have host-defined interfaces in their SuperTypes array. These interfaces require information that is unavailable to the RD-VBA host without a library reference to the library that defines these types.
For example, RD-VBA code that depends on the Microsoft Excel type library requires the Microsoft Excel type library in order to correctly resolve the members and expressions inside extensible (document) class modules.
Warning
Extensible modules cannot specify any Implements directives. RD-VBA must explicitly and statically deny Implements directives in extensible modules.
MS-VBA does not strictly enforce this rule. In MS-VBA, an Implements directive in an extensible module can cause host application instabilities, source project corruption, and host application crashes.
Such a directive should be detected statically, as an ordinary compile-time error.
2.4.2.2.2 Default Member
Members of a class can carry a VB_UserMemId attribute (see RD-VBAL §3.1.1 Attributes). A VB_UserMemId attribute 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.
The default member of a class type can be implicitly invoked through let-coercion, yielding the data value of the object; see RD-VBAL §5.5.1.2 Runtime semantics. When the default member also yields an object data type, the implicit invocation recurses as needed; see RD-VBAL §5.6.2 Expression Evaluation.
2.4.2.3 VBCollectionType
🧩 Object value types (inheriting VBObjectValue) that represent an instance of a collection type should implement IEnumerableObject.
VBCollectionType is a subclass of VBClassType that exposes a NewEnum member.
A VBCollectionType can be efficiently iterated using a For Each...Next loop structure; see RD-VBAL §5.4.2.4 For Each Statement.
Tip
For Each...Next enumeration is intended to be used with collections containing objects. Performance-related diagnostics should be issued when a VBCollectionType is accessed by index within the body of a For...Next loop; see RD-VBAL §5.4.2.3 For Statement.
Data Members
MS-VBAL sometimes refers to the elements (or items) of a collection as "data members". The term appears in error messages, e.g. VBR00461 MethodOrDataMemberNotFound.
RD-VBAL discards the "data member" terminology for collection elements, because it is confusing. In RD-VBA, a "member" is always a direct child symbol of a module, user-defined type, or enum.
Regardless of the error message content, RD-VBA must still raise the MS-VBA equivalent error code (e.g. VBR00461 MethodOrDataMemberNotFound) in the relevant contexts; see RD-VBAL §2.6.3 Runtime Errors.
2.4.2.4 VBProjectType
The symbol at the top of the abstract syntax tree (AST) of an entire VBA project is of a type inherited from VBProjectType.
The types inherited from VBProjectType correspond to the project types defined in MS-VBAL §4.1 Projects; see also RD-VBAL §4.0 Program Structure and Organization.
| Project type | Section |
|---|---|
| VBSourceProjectType | §2.4.2.4.1 |
| VBLibraryProjectType | §2.4.2.4.2 |
| VBHostProjectType | §2.4.2.4.3 |
2.4.2.4.1 VBSourceProjectType
VBSourceProjectType corresponds to the RD-VBA workspace folder (.rdproj) content; see RD-VBAL §2.2 RDPROJ Structure.
VBSourceProjectType represents the workspace source code of a VBA project.
2.4.2.4.2 VBLibraryProjectType
VBLibraryProjectType corresponds to a referenced library. A library project is referenced by a VBSourceProjectType (source project).
A VBLibraryProjectType project is defined in an implementation-defined manner. It exposes the types and members of the library to RD-VBA source code through the means available to any other VBA source code.
Through these means, workspace source code manipulates the library's objects and members as if they were defined in VBA source code. The library itself may or may not have been compiled from VBA source code.
2.4.2.4.3 VBHostProjectType
A VBHostProjectType project can be introduced into the RD-VBA environment by the host (rdc.exe) in an implementation-defined manner.
Additional workspace source code may be added to a host project if it is open ("an open host project"). Workspace source code is added to an open host project by agents other than the host application.
👉 An RDCoreReference for a reference to a
VBHostProjectTypeproject must have the "unremovable" flag set; see RD-VBAL §2.2.3 ProjectFile.
2.4.2.5 VBUnknownType
VBUnknownType is a special data type that represents an unresolved type. It is the fallback data type used when type resolution semantics fail to identify a valid data type for a given value.
Warning
An unknown type represents a compile-time binding failure, and should raise compile error VBC09311 UserDefinedTypeNotDefined; see RD-VBAL §2.6.2 Semantic Compilation Errors.
The UserDefinedTypeNotDefined wording can be confusing when it is raised for an unknown type. Verbose diagnostic messages should clarify its meaning in that case.
2.4.2.6 VBVoidType
VBVoidType is a special data type that represents the absence of return value semantics.
VBVoidType is the data type returned by Sub, Property Let, and Property Set procedures; see RD-VBAL §5.3.1.6 Subroutine and Function Declarations and RD-VBAL §5.3.1.7 Property Declarations.
👉 The internal representation of
VBVoidTypeis a managedInt32value (0), because the intent is to ultimately supportHRESULTinteroperability.
⏮️ RD-VBAL §2.4.1 Intrinsic Types | ⏭️ RD-VBAL §2.4.3 Meta and Advanced Types