Defines a simple procedure or event handler.
[ [Shared] ] Sub procedure_name [ <type_list> ] [ parameter_list ] [ Handles event_name ] [ Where generic_constraints ] [ statements ] End [ Sub ]
- Optional. Specifies that the procedure is associated with its surrounding object and not an instance of that object.
- Necessary name for the procedure.
- Optional. See Type List for more information.
- Optional. See Parameter List for more information.
- Optional. See the Handles keyword section for more information.
- Optional. See Where Clause (Generics) for more information.
- Completes the statement. You can also use End Sub.
Do not confuse the End Sub line with the Exit Sub statement.
Sub is short for "subroutine".
The Handles keyword 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.