<< Prev        Next >>

ID : 130

GoSub

Function

To jump to a label.

Syntax

GoSub label name

Guaranteed entry

Label name
Designate a label name.

Description

Jump to a designated label.

Jump destination will be limited within procedure.

You can use Return not like GoTo.

Related Terms

GoTo

Attention

-

Example

' !TITLE "Jump to Label Then Return to Origin of Jump"
' After the label jump, add 10 to aaa, return to origin of the jump, then add 20 to aaa
Sub Sample_GoSub

  Dim aaa As Integer

  aaa = 5

  ' Jump to LABEL1
  GoSub LABEL1

  aaa = aaa + 20

  ' Display "35" on the message output window
  PrintDbg aaa

  Exit Sub

LABEL1:

  aaa = aaa + 10

  ' Display "15" on the message output window 
  PrintDbg aaa

  ' Return to origin of the jump
  Return

End Sub

ID : 130

<< Prev        Next >>