advr.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
GOSUB...RETURN Statement Details
  Summary  Details                           Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
 GOSUB line-label-to
 .
 .
 .
 RETURN [line-label-resume]
 
 Usage Notes
   ■ The following discussion of subroutines applies only to the targets of
     GOSUB statements, not to SUB procedures delimited by SUB statements. In
     most cases, use the CALL statement to enter and exit subroutines.
     See: CALL Statement
 
   ■ In addition to RETURN with no argument, Visual Basic supports RETURN
     with a line label or line number. This support allows a return from a
     subroutine to the statement having the specified line label or number,
     instead of a return to the statement after the GOSUB statement. Use this
     line-specific method with care, since it is often difficult to read and
     debug.
 
   ■ You can call a subroutine any number of times in a program. You also
     can call a subroutine from within another subroutine. How deeply
     you can nest subroutines is limited only by the available stack space.
     Note: You can increase the stack space with the CLEAR statement.
     See: CLEAR Statement
 
   ■ Recursive subroutines - that is, subroutines that call themselves - can
     easily run out of stack space.
 
   ■ RETURN with a line label or line number can return control to a
     statement only in the module-level code, not in procedure-level code.
 
   ■ A subroutine can contain more than one RETURN statement. A simple RETURN
     statement (without the line-label-resume option) in a subroutine makes
     Visual Basic branch back to the statement following the most recent
     GOSUB statement.
 
   ■ Subroutines can appear anywhere in the program, but it is good
     programming practice to make them readily distinguishable from the
     main program. To prevent inadvertent entry into a subroutine, precede
     it with a STOP, END, or GOTO statement that directs program control
     around the subroutine.