On...GoSub Statement; On...GoTo Statement

Branches to one of several specified lines in the program code, depending on the value of a numeric expression.

Syntax:

On GoSub/GoTo syntax


On expression GoSub Label1[, Label2[, Label3[,...]]]
On expression GoTo Label1[, Label2[, Label3[,...]]]

Parameters:

expression: Any numeric expression between 0 and 255 that determines which of the lines the program branches to. If expression is 0, the statement is not executed. If expression is greater than 0, the program jumps to the label that has a position number that corresponds to the expression (1 = First label; 2 = Second label)

label: Target line according to GoTo or GoSub structure.

Note Icon

The GoTo or GoSub conventions are valid.


Example:


Sub ExampleOnGosub
Dim iVar As Integer
Dim sVar As String
    iVar = 2
    sVar =""
    On iVar GoSub Sub1, Sub2
    On iVar GoTo Line1, Line2
    Exit Sub
Sub1:
    sVar =sVar & " From Sub 1 to" : Return
Sub2:
    sVar =sVar & " From Sub 2 to" : Return
Line1:
    sVar =sVar & " Label 1" : GoTo Ende
Line2:
    sVar =sVar & " Label 2"
Ende:
    MsgBox sVar,0,"On...GoSub"
End Sub

Please support us!