Jumps to the specified label and continues execution until Return is encountered.

Gosub, Label



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. When that happens, the script jumps back to the first command beneath the Gosub and resumes execution there.



As with the parameters of almost all other commands, Label can be a variable reference such as %MyLabel%, in which case the name stored in the variable is used as the target. However, performance might suffer slightly because the target label must be "looked up" every time it is encountered rather than only once when the script is first loaded.

When using a dynamic label such as %MyLabel%, 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).

MsgBox, The Label1 subroutine is now running.