Branches to and returns from a subroutine.
GoSub line ... line ... Return |
The line argument can be any line label or line number.
You can use GoSub and Return anywhere in a procedure, but GoSub
and the corresponding Return statement must be in the same procedure.
A subroutine can contain more than one Return statement, but the first
Return statement encountered causes the flow of execution to branch back
to the statement immediately following the most recently executed GoSub
statement.
Also GoSub...Return can be used in global area of visibility.
Note: You can't enter or exit Sub/Function procedures with GoSub...Return.
Tip: Creating separate procedures that you can call may provide a more structured alternative to using GoSub...Return.
This example uses GoSub to call a subroutine within a Sub procedure. The Return statement causes the execution to resume at the statement immediately following the GoSub statement. The Exit Sub statement is used to prevent control from accidentally flowing into the subroutine.
Sub GosubDemo() |
See Also |
GoTo Statement, On..GoSub Statement, On...GoTo Statement, Sub Statement, Function Statement |