Defines a simple procedure or event handler.
[ Shared ] Sub name [ < typeList > ] [ parameterList ] [ Handles event ] [ Where genericConstraints ] [ statements ] End Sub
- Optional. Specifies that the procedure is associated with its surrounding object and not an instance of that object.
- Required identifier
- Optional. See Type List for details.
- Optional. See Parameter List for details.
- Optional. See the Handles clause section for details.
- Optional. See Where Clause (Generics) for details.
- End Sub
- Terminates the Sub block.
Do not confuse the End Sub clause with the Exit Sub statement.
Sub is short for "subroutine".
The Handles clause does two things for a Sub procedure. First, it modifies the procedure so it becomes an event handler. Secondly, it injects the parameters defined by the Event statement into the procedure where they become available, as if they were defined locally.