Sub Statement

Defines a simple procedure or event handler.

Syntax

[ [Shared] ] Sub procedure_name [ <type_list> ] [ parameter_list ] [ Handles event_name ]
    [ Where generic_constraints ]
    [ statements ]
End [ Sub ]

Parts

Shared
Optional. Specifies that the procedure is associated with its surrounding object and not an instance of that object.
procedure_name
Necessary name for the procedure.
type_list
Optional. See Type List for more information.
parameter_list
Optional. See Parameter List for more information.
Handles
Optional. See the Handles keyword section for more information.
generic_constraints
Optional. See Where Clause (Generics) for more information.
statements
Optional
End
Completes the statement. You can also use End Sub.

Instructions

Do not confuse the End Sub line with the Exit Sub statement.

Sub is short for "subroutine".

Handles keyword

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.

Examples

See also