5.6.16 Constrained Expressions
Note
This section describes the implementation of MS-VBAL §5.6.16 Constrained Expressions.
5.6.16.1 Constant Expressions
This section corresponds to MS-VBAL §5.6.16.1 Constant Expressions.
Note
Reserved. This section has no content yet.
5.6.16.2 Conditional Compilation Expressions
Note
This section describes the implementation of MS-VBAL §5.6.16.2 Conditional Compilation Expressions.
Precompiler constants are interpreted as Integer values. A precompiler constant value is a
PrecompilerConstantValue, an additional numeric data
value. See RD-VBAL §2.5.2.1.1 Numeric Values.
5.6.16.3 Boolean Expressions
This section corresponds to MS-VBAL §5.6.16.3 Boolean Expressions.
Note
Reserved. This section has no content yet.
5.6.16.4 Integer Expressions
This section corresponds to MS-VBAL §5.6.16.4 Integer Expressions.
Note
Reserved. This section has no content yet.
5.6.16.5 Variable Expressions
This section corresponds to MS-VBAL §5.6.16.5 Variable Expressions.
Note
Reserved. This section has no content yet.
5.6.16.6 Bound Variable Expressions
This section corresponds to MS-VBAL §5.6.16.6 Bound Variable Expressions.
A bound variable expression - the target of an LSet or an RSet statement, the control variable of a For or a
For Each loop, the string argument of a Mid statement, an input variable of an Input # statement - "is invalid if
it is classified as something other than a variable expression". A constant or a function of the library there is
VBC09333 (VariableRequired), whatever its declared type; see
RD-VBAL §5.4.3.8 Let Statement, which states the rule for the target of every
assignment, RD-VBAL §5.4.3.5 Mid Statement and
RD-VBAL §5.4.5 File Statements.
5.6.16.7 Type Expressions
This section corresponds to MS-VBAL §5.6.16.7 Type Expressions.
A type expression that is not a reserved data-type name binds under the type binding context
(RD-VBAL §2.3.1.3 Name Resolution), and is invalid if what it
binds is not a type: a user-defined type, an Enum type or a class is a type, and a procedural module or a project is
not. A type qualified by a module binds that module's own type, whatever else has its bare name: Mod2.Helpers, beside
a procedural module Helpers, is Mod2's type
(RD-VBAL §2.3.1.3 Name Resolution).
What a type expression binds that is no type is an error of its own, as MS-VBA has it (recorded in Excel), wherever a
type is written: the As clause of a declaration (a variable, a constant, a parameter, a result, a field of a
user-defined type, a local of any procedure), the As clause of a ReDim, and the type of a TypeOf ... Is
(RD-VBAL §5.6.7).
| It binds | Example | Error |
|---|---|---|
| A procedural module of the project | Dim g As Globals |
VBC09366 A module is not a valid type |
| A procedural module of a library | Dim s As Strings, Dim s As VBA.Strings |
VBC09373 Automation type not supported in Visual Basic |
| A project or a library | Dim p As VBA |
VBC09374 Expected user-defined type, not project |
| Nothing that is a type, or nothing at all | Dim w As Widgit |
VBC09311 User-defined type not defined |
New naming a procedural module is VBC09310 Type mismatch, as is New naming
anything else that binds but is not a class; New with a name nothing declares is VBC09311
(RD-VBAL §5.6.8 New Expressions).
An intrinsic type written where a value is (x = Long, Debug.Print Variant) is
VBC00001 Syntax error, as MS-VBA has it: a type is no value. Object is no
reserved type name there, and is read as a name, as MS-VBA reads it (Debug.Print Object is Variable not defined
under Option Explicit).
Note
Not implemented.
- The declared type of a field of a user-defined type, or of a local constant, is checked only for a module or a
project: a name that does not resolve there is not refused (
s As Missingin aType, orConst c As Missing = 1in a procedure, loads) (RD-VBAL §5.0 Semantics). - A declared type qualified by the name of the enclosing project is VBC09311 though it names a type, since the
qualifier does not resolve:
Dim w As Project1.Widget.
5.6.16.8 AddressOf Expressions
This section corresponds to MS-VBAL §5.6.16.8 AddressOf Expressions.
AddressOf <procedure> is an argument, and only an argument, as the grammar of MS-VBAL has it: x = AddressOf P is a syntax error, as it is in
MS-VBA. As in MS-VBA (recorded in Excel):
- Static semantics. What it names is a
Sub, aFunctionor aProperty Getof a standard module, named bare or qualified by its module,Privateones of the module it is written in included. A variable isVBC09364Expected Sub, Function, or Property, and a member of a class module or of an objectVBC09367Invalid use of AddressOf operator. Its declared type is implementation-defined: it is the environment'sLongPtr, which aLongPtror aVariantparameter takes - and aLongone does not, in a 64-bit environment (RD-VBAL §5.5.1.1). - Runtime semantics. It is the address of the procedure in the session's memory: never
0, the same every time, bare or qualified, and another for another procedure (RD-VBAL §2.3.1.2 Session Services). The address is made the first time it is asked for and lasts as long as the session; what is at it reads as zeros, and aPOKEthere is refused.
Note
🚧 Not implemented yet (*Ptr plan phase B): native code given the address - the callback of EnumWindows, say - has nothing it can call that runs the
procedure. In MS-VBA the procedure runs inside the native call, and an error raised in it is the error of the Declare call.
⏮️ RD-VBAL §5.6.15 With Expressions | ⏭️ RD-VBAL §6.0 Standard Library