5.3.1 Procedure Declarations

 subroutine-declaration = procedure-scope [initial-static] 
                "sub" subroutine-name [procedure-parameters] [trailing-static] EOS 
                         [procedure-body EOS] 
                [end-label] "end" "sub" procedure-tail 
  
 function-declaration = procedure-scope [initial-static] 
                         "function" function-name [procedure-parameters] [function-type] [trailing-static] EOS 
                  [procedure-body EOS] 
                   [end-label]  "end" "function" procedure-tail 
  
 property-get-declaration = procedure-scope [initial-static] 
                  "Property" "Get" 
                  function-name [procedure-parameters] [function-type] [trailing-static] EOS 
                            [procedure-body EOS] 
                            [end-label] "end" "property" procedure-tail 
  
 property-lhs-declaration = procedure-scope [initial-static] 
                  "Property" ("Let" / "Set") 
                   subroutine-name property-parameters [trailing-static] EOS 
               [procedure-body EOS] 
                  [end-label] "end" "property" procedure-tail 
  
 end-label = statement-label-definition 
 procedure-tail = [WS] LINE-END / single-quote comment-body /  ":" rem-statement 

Static Semantics

  • A function declaration implicitly defines a local variable, known as the function result variable, whose name and declared type are shared with the function and whose scope is the body of the function.

  • A function declaration defines a procedure whose name is the name value of its <function-name> and a subroutine declaration defines a procedure whose name is the name value of its <subroutine-name>

  • If the <function-name> element of a function declaration is a <TYPED-NAME> then the function declaration might not include a <function-type> element.

  • The declared type of a function declaration is defined as follows:

    • If the <function-name> element of a function declaration is a <TYPED-NAME> then the declared type of the function declaration is the declared type corresponding to the <type-suffix> of the <TYPED-NAME> as specified in section 3.3.5.3.

    • If the <function-name> element of a function declaration is not a <TYPED-NAME> and the function declaration does not include a <function-type> element its declared type is its implicit type as specified in section 5.2.3.1.5.  

    • If a function declaration includes a <function-type> element then the declared type of the function declaration is the specified type of the <function-type> element.

  • The declared type of a function declaration that is part of a <class-module-code-section> might not be an UDT that is defined by a <private-type-declaration>.

  • The declared type of a function declaration might not be a private enum name.

  • If the optional <end-label> is present, its <statement-label> MUST have a label value that is different from the label value of any <statement-label> defined within the <procedure-body>.

     

    Runtime Semantics

  • The code contained by a procedure is executed during procedure invocation.

  • Each invocation of a procedure has a distinct variable corresponding to each ByVal parameter or procedure extent variable declaration within the procedure.

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

  • A function result variable has procedure extent.

  • Within the <procedure-body> of a procedure declaration that is defined within a <class-module-code-section> the declared type of the reserved name Me is the named class defined by the enclosing class module and the data value of "me" is an object reference to the object that is the target object of the currently active invocation of the function.

  • Procedure invocation consists of the following steps:

    1. Create procedure extent variables corresponding to ByVal parameters.

    2. Process actual invocation augments as defined in section 5.3.1.11.

    3. Set the procedure’s error handling policy (section 5.4.4) to the default policy.

    4. Create the function result variable and any procedure extent local variables declared within the procedure.

    5. Execute the <procedure-body>.

    6. If the procedure is a function, return the data value of the result variable to the invocation site as the function result.

    7. The invocation is complete and execution continues at the call site.