5.3.1.5 Parameter Lists

 procedure-parameters = "(" [parameter-list] ")" 
 property-parameters = "(" [parameter-list ","] value-param ")" 
  
 parameter-list = (positional-parameters "," optional-parameters ) / 
                  (positional-parameters  ["," param-array]) / 
                  optional-parameters / 
                  param-array  
  
 positional-parameters = positional-param *("," positional-param) 
 optional-parameters = optional-param *("," optional-param) 
 value-param = positional-param 
 positional-param = [parameter-mechanism] param-dcl 
 optional-param = optional-prefix param-dcl [default-value] 
 param-array = "paramarray" IDENTIFIER "(" ")" ["as" ("variant" / "[variant]")] 
  
 param-dcl = untyped-name-param-dcl / typed-name-param-dcl 
 untyped-name-param-dcl = IDENTIFIER [parameter-type]  
 typed-name-param-dcl = TYPED-NAME [array-designator] 
 optional-prefix = ("optional" [parameter-mechanism]) / ([parameter-mechanism] ("optional")) 
 parameter-mechanism = "byval" / " byref" 
 parameter-type = [array-designator] "as" (type-expression / "Any") 
 default-value = "=" constant-expression 

Static Semantics

  • A <parameter-type> element only include the keyword Any if the <parameter-type> is part of a <external-proc-dcl>.

  • The name value of a <typed-name-param-dcl> is the name value of its <TYPED-NAME> element.

  • The name value of an <untyped-name-param-dcl> is the name value of its <IDENTIFIER> element.

  • The name value of a <param-dcl> is the name value of its constituent <untyped-name-param-dcl> or <typed-name-param-dcl> element.

  • The name of a <positional-param> or a <optional-param> element is the name value of its <param-dcl> element.

  • The name of a <param-array> element is the name value of its <IDENTIFIER> element.

  • Each <positional-param>, <optional-param>, and <param-array> that are elements of the same <parameter-list>, <property-parameters>, or <event-parameter-list> MUST have a distinct names.

  • The name of each <positional-param>, <optional-param>, and <param-array> that are elements of a function declaration MUST be different from the name of the function declaration.

  • The name value of a <positional-param>, <optional-param>, or a <param-array> might not be the same as the name of any variable defined by a <local-variable-declaration>, a <static-variable-declaration>, a <redim-statement>, or a <local-const-declaration> within the <procedure-body> of the containing procedure declaration.

  • The declared type of a <positional-param>, <optional-param>, or <value-param> is the declared type of its constituent <param-dcl>.

  • The declared type of a <param-dcl>that consists of an <untyped-name-param-dcl>is defined as follows:

    • If the optional <parameter-type> element is not present, the declared type is the implicit type of the <IDENTIFIER> as specified in section 5.2.3.1.5.

    • If the specified optional <parameter-type> element is present but does not include an <array-designator> element the declared type is the declared type referenced by its <type-expression> element.

    • If the specified optional <parameter-type> element is present and includes an <array-designator> element the declared type is resizable array whose element type is the declared type referenced by its <type-expression> element.

  • The declared type of a <param-dcl> that consists of a <typed-name-param-dcl> is defined as follows:

    • If the optional <array-designator> element is not present the declared type is the declared type corresponding to the <type-suffix> of the <TYPED-NAME> as specified in section 3.3.5.3.

    • If the optional <array-designator> element is present then the declared type of the defined variable is resizable array with a declared element type corresponding to the <type-suffix> of the <TYPED-NAME> as specified in section 3.3.5.3.

  • The declared type of a <param-dcl> that is contained in an event declaration or a public procedure declaration in a <class-module-code-section> might not be a private UDT, a public UDT defined in a procedural module, or a private enum name.

  • The declared type of an <optional-param> might not be an UDT.

  • If the declared type of an <optional-param> is not Variant and its type was implicitly specified by an applicable <def-directive>, it MUST have a <default-value> clause specified.

  • A <default-value> clause specifies the default value of a parameter. If a <default-value> clause is not specified for a Variant parameter, the default value is an implementation-defined error value that resolves to standard error code 448 (“Named argument not found”). If a <default-value> clause is not specified for a non-Variant parameter, the default value is that of the parameter’s declared type.

  • A <positional-param> or <optional-param> element that does not include a <parameter-mechanism> element has the same meaning as if it included a <parameter-mechanism> element consisting of the keyword ByRef.

  • A <param-dcl> that includes a <parameter-mechanism> element consisting of the keyword ByVal might not also include an <array-designator> element.

  • The declared type of the <IDENTIFIER> of a <param-array>is resizable array of Variant.

    Runtime Semantics

  • Each invocation of a function has a distinct function result variable.

  • A function result variable has procedure extent.

  • Each <positional-param> or <optional-param> that includes a <parameter-mechanism> element consisting of the keyword ByVal defines a local variable with procedure extent and whose declared type is the declared type of the constituent <param-dcl> element. The corresponding parameter name is bound to the local variable.

  • Each <positional-param> that includes a <parameter-mechanism> element consisting of the keyword ByVal defines a local name binding to a pre-existing variable corresponding to the corresponding positional argument.

  • Each <optional-param> that includes a <parameter-mechanism> element consisting of the keyword ByRef defines a local variable with procedure extent and whose declared type is the declared type of the constituent <param-dcl> element.

    • If an invocation of the containing procedure does not include an argument corresponding to the <optional-param> the parameter name is bound to the local variable for that invocation.

    • If an invocation of the containing procedure includes an argument corresponding to the <optional-param> the parameter name is locally bound to the pre-existing variable corresponding to the argument.

  • Upon invocation of a procedure the data value of the constituent <default-value> element of each <optional-param> that does not have a corresponding argument is assigned to the variable binding of the parameter name of the <optional-param>.

  • Each procedure that is a method has an implicit ByVal parameter called the current object that corresponds to the target object of an invocation of the method. The current object acts as an anonymous local variable with procedure extent and whose declared type is the class name of the class module containing the method declaration. For the duration of an activation of the method the data value of the current object variable is target object of the procedure invocation that created that activation. The current object is accessed using the Me keyword within the <procedure-body> of the method but cannot be assigned to or otherwise modified.

  • If a <parameter-list> of a procedure contains a <param-array> element, then each invocation of the procedure defines an entity called the param array that behaves as if it was an array whose elements were “byref” <positional-param> elements whose declared types were Variant. An access to an element of the param array behaves as if it were an access to a named positional parameter. Arguments are bound to the elements of a param array as defined in section 5.3.1.11.