5.3.1.6 Subroutine and Function Declarations
Note
This section describes the implementation of MS-VBAL §5.3.1.6 Subroutine and Function Declarations.
Static Semantics
VBVoidType is the data type returned by Sub,
Property Let and Property Set procedures; see
RD-VBAL §2.4.2 Non-intrinsic Types.
A Sub's own symbol already carries VBVoidType as its type. See
RD-VBAL §5.6.10 Simple Name Expressions.
Function Result Variable
Function and Property Get return values (the function result variable) follow
MS-VBAL §5.3.1 Procedure Declarations.
- Each invocation of a
FunctionorProperty Getgets a fresh function result variable. - The function result variable is modeled as
ICallStackFrame
.ReturnValue, a single per-activation slot. ICallStackFrame.ReturnValueis read-only on the SDK interface, likeICallStackFrame.Pc; it is mutable on the runtime'sCallStackFrame.ReturnValueis seeded to the default value of the procedure's declared return type before the procedure body runs.
Inside the procedure's own body, a bare reference to the procedure's own name is the function result variable:
| Use of the procedure's own name, from within its own body | Effect | Described in |
|---|---|---|
| A bare reference | Reads the ReturnValue slot instead of the general symbol table. |
RD-VBAL §5.6.10 Simple Name Expressions |
| A Let-assignment to a bare reference | Assigns the ReturnValue slot instead of the general symbol table. |
RD-VBAL §5.4.3.8 Let Statement |
| A Set-assignment to a bare reference | Set-coerces the object to the declared result type, and assigns the ReturnValue slot: the result of a Variant function that is Set to an object holds the object. |
RD-VBAL §5.4.3.9 Set Statement |
A function that returns an object and never sets its result returns Nothing, which is the default value of an object type.
The object a function returns is not released with the activation's locals, whether the result is declared as an object
type or as a Variant that holds the object.
Invocation Result
| Procedure | Result of a successful invocation |
|---|---|
Function, Property Get |
The value of its own function result variable. |
Sub |
VBVoidValue |
RuntimeProcedureInvoker reads frame.ReturnValue back once ExitProcedure is reached, and reports it as the
call's result. See
RD-VBAL §5.3.1.11 Procedure Invocation Argument Processing.
A Function or Property Get that declares no parameters is not given the arguments written after it in parentheses:
it is called without them, and they index what it returns. Items(1) of a function that returns a Collection is
Items().Item(1), as h.Items(1) is h.Items.Item(1) for a property. The empty list of F() is not an argument.
⏮️ RD-VBAL §5.3.1.5 Parameter Lists | ⏭️ RD-VBAL §5.3.1.7 Property Declarations