Sub Statement

Defines a simple procedure or event handler.

Syntax

[ Shared ] Sub name [ < typeList > ] [ parameterList ] [ Handles event ]
    [ Where genericConstraints ]
    [ statements ]
End Sub

Parts

Shared
Optional. Specifies that the procedure is associated with its surrounding object and not an instance of that object.
name
Required identifier
typeList
Optional. See Type List for details.
parameterList
Optional. See Parameter List for details.
Handles
Optional. See the Handles clause section for details.
genericConstraints
Optional. See Where Clause (Generics) for details.
statements
Optional
End Sub
Terminates the Sub block.

Remarks

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

Sub is short for "subroutine".

Handles clause

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.

Examples

See also