Table of Contents

2.4.1 Intrinsic Types

In RD-VBA, a type is an intrinsic type if MS-VBAL mentions it. Whether a type is an intrinsic type does not depend on its specified semantics, nor on how RD-VBA models it.

VBIntrinsicType is the type-system abstraction that formalizes this classification; see RD-VBAL §2.4 Static Types.

Non-numeric Intrinsic Types

The non-numeric intrinsic types are:

Type Notes
VBArrayType Array types; see §2.4.1.3.
VBFixedSizeArrayType Array type; see §2.4.1.3.
VBResizableArrayType Array type; see §2.4.1.3.
VBResizableByteArrayType Array type; see §2.4.1.3.
VBBooleanType
VBDateType
VBEmptyType
VBErrorType
VBLongPtrType_x64 LongPtr; see LongPtr.
VBLongPtrType_x86 LongPtr; see LongPtr.
VBMissingType
VBNullType
VBObjectType
VBStringType String type; see §2.4.1.2.
VBFixedStringType String type; see §2.4.1.2.
VBVariantType

LongPtr

LongPtr is a different type in each pointer width: VBLongPtrType_x64 for a 64-bit pointer width, and VBLongPtrType_x86 for a 32-bit pointer width. The pointer width belongs to the environment; see RD-VBAL §6.0 Standard Library.

The data value type VBLongPtrValue has the VBType VBLongPtrType_x64 or VBLongPtrType_x86. Which of the two it has depends on the host environment; see RD-VBAL §2.5.2.1 Intrinsic Type Values.

2.4.1.1 VBNumericType

Numeric types are intrinsic types that represent a numeric value, regardless of the value's representation. VBNumericType is the type-system abstraction that formalizes this classification.

Every numeric type additionally implements one of three marker interfaces:

Marker interface Implemented by
IIntegralNumericType All integer types
IFixedPointNumericType All fixed-point numeric types
IFloatingPointNumericType All floating-point numeric types

The table of intrinsic numeric data types below shows the managed (.NET) minimum and maximum values, for simplicity.

Type Interface Description MinValue MaxValue
VBByteType IIntegralNumericType 8-bit Byte unsigned integer Byte.MinValue (0) Byte.MaxValue (255)
VBIntegerType IIntegralNumericType 16-bit Integer signed integer Int16.MinValue (-32,768) Int16.MaxValue (32,767)
VBLongType IIntegralNumericType 32-bit Long signed integer Int32.MinValue (-2,147,483,648) Int32.MaxValue (2,147,483,647)
VBLongLongType IIntegralNumericType 64-bit LongLong signed integer Int64.MinValue (-9,223,372,036,854,775,808) Int64.MaxValue (9,223,372,036,854,775,807)
VBSingleType IFloatingPointNumericType 32-bit single-precision floating-point Single.MinValue Single.MaxValue
VBDoubleType IFloatingPointNumericType 64-bit double-precision floating-point Double.MinValue Double.MaxValue

Floating-point types also define a SignificantIntegerDigits; see RD-VBAL §2.5.2.1.1 Numeric Values.

2.4.1.2 VBStringType

String types are internally represented using a UTF-16 standard .NET System.String value.

The string types are:

  • VBStringType
  • VBFixedStringType

The data of a string is its UTF-16 code units, two bytes each, little-endian. That data can also be an odd number of bytes: a Byte() of any length let-coerces to a String (RD-VBAL §5.5.1.2.6 Let-coercion to and from resizable Byte()). A System.String cannot hold half a code unit, so the byte left over after the last whole character is held beside it: the runtime value of such a string is a VBRuntimeByteStringValue, its whole characters and its trailing byte. A string of whole characters keeps the plain runtime value it has always had. VBStringValue gives the data of either as bytes (GetBytes, ByteLength), and makes a String of any bytes (FromBytes), every byte kept, a lone surrogate included. Two strings that differ only in a trailing byte are different values.

Reads a String as Where
Its bytes, a trailing byte included LenB; let-coercion to String from a String (a copy) and to and from Byte(); &, and + between two Strings; the relational operators; the MidB statement, and the Mid statement, which keeps a trailing byte it does not replace; a standard-library member's String argument.
Its whole characters Len; Print, Print #, Write # and Put; the numeric, Boolean and Date conversions; LSet, RSet and a fixed-length String; Like; a Declared procedure's String argument, and the String and String * n fields of a record passed to one; a String passed to an automation server.

👉 The debugger shows a String's characters: a trailing byte is not displayed.

2.4.1.3 VBArrayType

Array types include the following implementations of VBArrayType:

  • VBFixedSizeArrayType
  • VBResizableArrayType
  • VBResizableByteArrayType

An array type does not encode any dimensions.

The value associated with an array type encodes the array dimensions; see VBArrayValue and its derived types, and RD-VBAL §2.5.2.1.2 Array Values. On every read after the array value is stored, VBArrayType.CreateValue(IBindingHandle) unboxes it unchanged.

Resizable Byte Arrays

If the item type of a resizable array value is VBByteType, the data type of the array is VBResizableByteArrayType.

VBResizableByteArrayType has specific let-coercion semantics attached, allowing implicit conversion to and from VBStringType; see RD-VBAL §5.5.1.2 Runtime semantics.

ReDim

Array value ReDim
VBFixedSizeArrayValue Illegal with any VBFixedSizeArrayValue.
VBResizableArrayValue May declare a VBResizableArrayValue, or redimension an already-declared VBResizableArrayValue.

For the re-dimension of an existing array, the implicit declaration by an unqualified ReDim target, and ReDim bounds, see RD-VBAL §5.4.3.3 ReDim Statement.

Declared Array Types

The declaration pass binds the declared type of an array symbol from the array-dim clause alone (MS-VBAL §5.2.3.1.3 Array Dimensions and Bounds), before any bound is evaluated:

Array-dim clause Example Declared type
One or more bounds Dim g(1 To 3, 0 To 4) As Long VBFixedSizeArrayType
Empty () clause Dim b() As Long VBResizableArrayType
Empty () clause, with item type Byte Dim b() As Byte VBResizableByteArrayType (instead of VBResizableArrayType)

A trailing () on the As clause (As Long()) is the type of what a Function, a Property Get or a Declare's Function returns, an array of it; it is a syntax error on a variable (RD-VBAL §5.2.3.1.3).

An omitted array item type defaults to Variant (MS-VBAL §5.2.3.1 Module Variable Declaration Lists). This default is applied by a later normalization pass, not by the declaration pass.

The declaration pass keeps each array bound verbatim, as declared. The following are the concern of the semantic pass that materializes the array value (RD-VBAL §2.5.2.1.2 Array Values):


⏮️ RD-VBAL §2.4 Static Types | ⏭️ RD-VBAL §2.4.2 Non-intrinsic Types