Sub Statement

Defines a private 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 modifier specifies that the procedure is a member of its container, and not an instance of that container.
procedure_name
Mandatory name for the procedure.
type_list
Optional one or more names with a comma between each, all between brackets ([ ]). See Type List for more information.
parameter_list
Optional one or more declarators with a comma between each, optionally between parentheses. See Parameter List for more information.
Handles
Optional keyword to make an event handler. See the Handles keyword section for more information.
generic_constraints
Optional. See Where Clause (Generics) for more information.
statements
Optional one or more executable statements.
End
Completes the statement. You can also use End Sub.
You can change this part of the syntax. See @Option Directive for more information.

Instructions

End Sub is not the same as Exit Sub.

Sub is short for “subroutine”.

Handles keyword

The keyword Handles does two things for the construct Sub. First, it changes the procedure so it becomes an event handler. Secondly, it injects the parameters defined by a statement Event into the procedure where they become available, as if they were defined locally.

Examples

TODO

See also