Jumps to the specified label and continues execution until Return is encountered.
Gosub LabelCommand Example: Gosub "MyLabel" Function Example: Gosub("Label")
The name of the label, hotkey label, or hotstring label to which to jump, which causes the commands beneath Label to be executed until a Return or Exit is encountered. "Return" causes the script to jump back to the first command beneath the Gosub and resume execution there. "Exit" terminates the current thread.
Label can be a variable or expression only if parentheses are used. For example,
Gosub MySub and
Gosub("MySub") both execute the
Performance is slightly reduced when using a dynamic label (that is, a variable or expression which returns a label name) because the target label must be "looked up" each time rather than only once when the script is first loaded. An error dialog will be displayed if the label does not exist. To avoid this, call IsLabel() beforehand. For example:
if IsLabel(VarContainingLabelName) Gosub(VarContainingLabelName)
Although Gosub is useful for simple, general purpose subroutines, consider using functions for more complex purposes.
Return, Functions, IsLabel, Blocks, Loop, Goto
Gosub, Label1 MsgBox "The Label1 subroutine has returned (it is finished)." return Label1: MsgBox "The Label1 subroutine is now running." return