Jumps to a subroutine (subsection)
A subsection is a user defined command section that begins with "[Sub_SubSectionName_Begin]" and ends with "[Sub_SubSectionName_End]". Use subsections when the same code should be executed more than once in a script or to get more readable code.
Status markers are written in subsections the same way as in normal command sections - it is possible to retry failing commands in subsections. Markers in subsections are deleted when markers in a calling main command section are deleted.
After a subsection is successfully executed, status markers in the subsection are deleted and the script resumes at the line following the latest GoSub.
A subsection can not contain a jump to itself, nor can subsections call each other in an infinite loop.
Related topic: $c pre-command switch - call a subsection before a command is executed
Category
General
Script section
All
GoSub SubSectionName
SubSectionName
Name of subsection to jump to
Example
Two subroutines. First one called both from [Batch] section and second subroutine. Second subroutine called from loop in [Batch] section.
[Settings_Begin]
BatchSettings.Delimiter=;
BatchSettings.MarkerCol=3
[Settings_End]
[Sub_Hello_Begin]
MessageBox Hello
[Sub_Hello_End]
[Sub_CheckItem_Begin]
if %col1%=Item1 then
MessageBox First item
Else
MessageBox Second item
EndIf
GoSub Hello
[Sub_CheckItem_End]
[Batch_Begin]
GoSub Hello
Data.Loop
GoSub CheckItem
Data.EndLoop
[Batch_End]
[Data_Begin]
Item1
Item2
[Data_End]
Result: "Hello" -> "First item" -> "Hello" -> "Second item" -> "Hello"