Table of Contents

6.0 Standard Library

This chapter describes the RD-VBA implementation of the VBA standard library, MS-VBAL §6 VBA Standard Library.

The VBA project consists of a set of classes, functions, Enum types and constants that together form VBA's standard library (RD-VBAL §6.1 VBA Project).

🎯 The RDCore platform must implement the VBA standard library. The environment host shall inject the standard library's symbols into all VBA projects, and those symbols shall carry the appropriate return type metadata.

The SDK defines the interfaces for the internal representation of each standard-library module (RDCore.SDK.Runtime.Abstract.StdLib). The environment host exposes the symbols provided by the standard library to the workspace.

A session is composed from several symbol providers: configuration flags, AST declarations, reflected referenced libraries, and the environment host's own runtime and standard library (RD-VBAL §2.3.1.2 Session Services).

The following standard-library topics are described with their module or class:

Topic Described in
The Err function, and the shape of the error object it returns RD-VBAL §6.1.3.2 Err Class
🧩 ErrObject.StackTrace RD-VBAL §6.1.3.2.2.7 StackTrace
🧩 Information.Erl RD-VBAL §6.1.2.7.1.14 Erl
Strings.Len / Strings.LenB RD-VBAL §6.1.2.11.1.22 Len / LenB
The VBScript RegExp 5.5 class modules RD-VBAL §6.2 VBScript Regular Expressions

Standard-Library Calls

Most of the standard library declares Variant parameters. A standard-library member's Variant parameter accepts its argument.

An argument of a standard-library call reaches the member as follows:

  1. The evaluator coerces the argument to the parameter's declared type on the way in (RD-VBAL §5.3.1.11 Procedure Invocation Argument Processing).
  2. The external call carries the argument as an IRuntimeValue: a runtime value rather than a typed value.
  3. At external dispatch, the typed value of a Variant argument is taken off the runtime variant itself (VBRuntimeVariantValue), not from its BoxedValue. A Variant's own BoxedValue unwraps all the way to the managed value (RD-VBAL §2.5.2.1.5 Variant Values).

The declared type of an argument survives external dispatch, because each intrinsic type stores its own exact managed type: a short for Integer and an int for Long (RD-VBAL §2.5.2.1.1 Numeric Values).

👉 Because each intrinsic stores its exact managed type, Len returns "the number of bytes required to store a variable" (RD-VBAL §6.1.2.11.1.22 Len / LenB).

6.0.1 Symbol Injection

The SDK declarations are the standard library's definition. The standard library's symbols are read off those declarations by StdLibSymbolReader.

A standard-library module's members, their names, their parameters and their return types all come from the signature an implementation has to satisfy. Each of them is stated once, in that SDK signature.

👉 Because the symbols are read off the SDK signatures, a symbol the workspace resolves cannot describe a member the runtime does not have.

Return Types

A standard-library declaration states its return type in its own signature:

Declaration result type Return type of the member
RuntimeSemanticsEvaluationResult<TValue> Stated: TValue names the value the member produces.
RuntimeSemanticsEvaluationResult (non-generic) None. This is what makes the member a Sub.

Attributes

An attribute states what a declaration's signature cannot express, and is used only where it applies.

Attribute Carries
StdLibModuleAttribute Marks a declaration as a standard-library module, and may name it.
StdLibClassAttribute Marks a declaration as a standard-library class, and may name it.
StdLibEnumAttribute Marks a declaration as a standard-library enum, and may name it. FormShowConstants is a name no naming convention recovers, so the attribute states it.
StdLibMemberAttribute Any of: a member name no naming convention recovers (for example Hex beside Hex$); an accessor kind (StdLibMemberKind); a return type that is a class or an enum rather than an intrinsic type; whether the member is hidden; a VB_UserMemId (0 for the default member of a class, -4 for its enumeration member), which is what a workspace class says with Attribute Item.VB_UserMemId = 0.
StdLibArrayAttribute The element type of an array parameter (ValueArray() As Double), which VBResizableArrayValue alone reads as Variant(). It is refused on anything but a required ByVal array parameter.

Naming Conventions

A standard-library name that follows a naming convention needs no attribute:

SDK declaration Standard-library name
Interface IStdInformationModule Module Information
Enum VBDayOfWeek Enum VbDayOfWeek
Enum member VBSunday Constant vbSunday

No Reference, No Opt-In

Nothing references the standard library, and nothing opts into it. The standard-library modules a project gets are the SDK declarations that carry a marker attribute.

A project has the standard library's symbols whether or not its .rdproj mentions the library (RD-VBAL §2.2.3 ProjectFile).

rdcore/host/symbols/define resolves a declared type name against the standard library's own types as well as the intrinsic types (RD-VBAL §2.0.2 Client/Server Capabilities).

Library Name

The standard library is a project of its own, named VBA in every language (StdLibSymbolProvider.LibraryName): it is what a project-qualified reference to the library names (VBA.Strings.LenB, VBA.LenB; MS-VBAL §5.6.12), and what the library's members say they belong to (SymbolProperties.Library).

VB6 loads the very same VBA library. The VB library of VB6 is another thing: the runtime library of its ActiveX controls (VB.Form, VB.TextBox...), which the platform does not model.

Note

Not implemented. The library is the same whole in every language (SupportedLanguage). Where a language has more or fewer members than another - VB6 has VBA-only members the platform does not hide from it, and a BASIC has no library of its own to speak of - the intent is for the members to say which languages they belong to, with an attribute on the declaration, and not for the library to change its name.

Pointer Width

CLngPtr needs the one thing a standard-library declaration cannot state: its LongPtr return type depends on the pointer width. LongPtr is a different type in each pointer width (RD-VBAL §2.4.1 Intrinsic Types; RD-VBAL §6.1.2.3.1.10 CLngPtr).

The pointer width belongs to the environment. The environment host passes StdLibSymbolProvider the pointer width of its own runtime profile (IRuntimeEnvironmentProfile).


⏮️ RD-VBAL §5.6.16 Constrained Expressions | ⏭️ RD-VBAL §6.1 VBA Project