Home > Language Reference > Program Flow Functions > Sub

Sub

The Sub...EndSub statement declares the name, parameters and included statements that define a procedure (sub-program).

Usage

Used to process the same actions at different points in a script.

Syntax

Sub <sub_name>([<param1>[,<param2>]....])
        [Local <variable_name>]
        <statements>
        ...
        [ExitSub]
        ...
    EndSub

Parameters

<sub_name>, label, constant, name of the sub. Max length of a Sub name is 32 characters.

<param1>, <param2>, optional string or integer, parameters of the Sub. Parameters are passed by reference, not by value.

Local, keyword. Used to define Local variables inside the Sub.

ExitSub, keyword. Used to exit the Sub at this step.


See also
Function
Script Structure
Global and Local Variables

Example

Sub my_routine()
        ret=msgbox("Would you like to leave the subroutine?",4,"EXAMPLE")
    If ret=6 then
       ' Exit the subroutine if the user has clicked the OK button in the dialog box
        ExitSub
        endif
msgbox("I'm in my subroutine")
EndSub

'Subroutine call
    my_routine()

msgbox("Script END!")