Return Statement

Syntax

GoSub label
...
label

Return

label

Use: Required

A subroutine label within a procedure.

Description

Branches back to a calling GoSub statement after executing a subroutine within a procedure.

Rules at a Glance

  • A subroutine can include an number of Return statements.

  • Return branches back to the statement immediately following the last executed GoSub statement in the current subroutine.

  • A GoSub statement and the subroutine it calls must reside within the same procedure.

Programming Tips and Gotchas

The Return statement is only included in this book for completeness, should you have to maintain legacy code; otherwise, you shouldn't be writing new code using the GoSub...Return statements, since it tends to create "spaghetti" code that is very difficult to read and to maintain. Code should be rewritten using separate procedures.

See Also

GoSub Statement

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.