5.6.2.1 Evaluation to a data value

Static semantics. The following types of expressions can be evaluated to produce a data value:

  • An expression classified as a value expression or variable expression can be evaluated as a data value with the same declared type as the expression, based on the following rules:

    • If this expression’s argument list queue is empty, the declared type of the data value is that of the value.

    • Otherwise, if this expression’s argument list queue has a first unconsumed argument list (perhaps with 0 arguments):

      • If the declared type of the expression is Object or Variant, the declared type of the data value is Variant.

      • If the declared type of the expression is a specific class:

        • If the declared type of the variable has a public default Property Get or function and this default member’s parameter list is compatible with this argument list, the declared type of the data value is the declared type of this default member.

        • Otherwise, the evaluation is invalid.

      • If the declared type of the expression is an array type:

        • If the number of arguments specified is equal to the rank of the array, the declared type of the data value is the array’s element type.

        • Otherwise, if one or more arguments have been specified and the number of arguments specified is different than the rank of the array, the evaluation is invalid.

      • Otherwise, if the declared type is a type other than Object, Variant, a specific class or an array type, the evaluation is invalid.

  • An expression classified as a property with an accessible Property Get or a function can be evaluated as a data value with the same declared type as the property or function.

  • An expression classified as an unbound member can be evaluated as a data value with a declared type of Variant.

Runtime semantics.

At runtime, the data value’s value is determined based on the classification of the expression, as follows:

  • If the expression is classified as a value, the data value’s value is that of the expression.

  • If the expression is classified as an unbound member, the member is resolved as a variable, property, function or subroutine:

    • If the member was resolved as a variable, property or function, evaluation continues as if the expression had statically been resolved as a variable expression, property expression or function expression, respectively. 

    • If the member was resolved as a subroutine, the subroutine is invoked with the same target and argument list as the unbound member expression. The data value’s value is the value Empty.

  • If the expression is classified as a variable:

    • If the argument list queue is empty, the data value’s value is a copy of the variable’s data value.

    • Otherwise, if the argument list queue has a first unconsumed argument list (perhaps empty):

      • If the value type of the expression’s target variable is a class:

        • If the declared type of the target is Variant, runtime error 9 (Subscript out of range) is raised.

        • If the declared type of the target is not Variant, and the target has a public default Property Get or function, the data value’s value is the result of invoking this default member for that target with this argument list. This consumes the argument list.

        • Otherwise, runtime error 438 (Object doesn’t support this property or method) is raised.

      • If the value type of the expression’s target is an array type:

        • If the number of arguments specified is equal to the rank of the array, and each argument is within its respective array dimension, the data value’s value is a copy of the value stored in the element of the array indexed by the argument list specified. This consumes the argument list.

        • Otherwise, runtime error 9 (Subscript out of range) is raised.

      • Otherwise, if the value type of the expression’s target variable is a type other than a class or array type, runtime error 9 (Subscript out of range) is raised.

  • If the expression is classified as a property or a function:

    • If the enclosing procedure is either a Property Get or a function, and this procedure matches the procedure referenced by the expression, evaluation restarts as if the expression was a variable expression referencing the current procedure’s return value.

    • Otherwise, the data value’s value is the result of invoking this referenced property’s named Property Get procedure or function for that target. The argument list for this invocation is determined as follows:

      • If the procedure being invoked has a parameter list that cannot accept any parameters or the argument queue is empty, the procedure is invoked with an empty argument list. In this case, if the argument queue has a first unconsumed argument list and this list is empty, this argument list is consumed.

      • Otherwise, if the procedure being invoked has a parameter list with at least one named or optional parameter, and the argument list queue has a first unconsumed argument list (perhaps empty), the procedure is invoked with this argument list. This consumes the argument list.