5.3.1.8 Event Handler Declarations

 event-handler-name = IDENTIFIER 

Static Semantics

  • A procedure declaration qualifies as an event handler if all of the following are true:

    • It is contained within a class module.

    • The name value of the subroutine name MUST begin with an event handler name prefix corresponding to a WithEvents variable declaration within the same class module as the procedure declaration. The variable defined by the corresponding variable declaring declaration is called the associated variable of the event handler.

    • The procedure name text that follows the event handler name prefix MUST be the same as an event name defined by the class that is the declared type of the associated variable. The corresponding <event-declaration> is the handled event.

  • An event handler is invalid if any of the following are true:

    • The procedure declaration is not a <subroutine-declaration>.

    • Its <parameter-list> is not compatible with the <event-parameter-list> of the handled event. A compatible <parameter-list> is one that meets all of the following criteria:

      • The number of <positional-parameters> elements MUST be the same.

      • Each corresponding parameter has the same type and parameter mechanism. However, corresponding parameters can differ in name and in whether the <parameter-mechanism> is specified implicitly or explicitly.