LibreOffice 7.6 Help
Calls a subroutine that is indicated by a label inside a Sub or a Function. The statements following the label are executed until the next Return statement. Afterwards, the program continues with the statement that follows the GoSub statement.
GoSub label[:]
label: A line identifier indicating where to continue execution. The scope of a label in that of the routine it belongs to.
The GoSub statement calls a local subroutine indicated by a label from within a subroutine or a function. The name of the label must end with a colon (":").
Sub/Function foo
' statements
GoSub label
' statements
Exit Sub/Function
label:
' statements
Return
End Sub/Function
āϝāĻĻāĻŋ āĻĒā§āϰā§āĻā§āϰāĻžāĻŽāĻāĻŋāϤ⧠āĻāĻŽāύ āĻāĻāĻāĻŋ āĻĒā§āϰāĻĻāĻžāύ āϏā§āĻā§āĻāĻŽā§āύā§āĻ āĻĨāĻžāĻā§ āϝāĻžāϰ āĻĒā§āϰā§āĻŦā§ GoSub āĻŦāĻŋāĻĻā§āϝāĻŽāĻžāύ āύā§, āϤāĻžāĻšāϞ⧠LibreOffice āĻŦā§āϏāĻŋāĻ āĻāĻāĻāĻŋ āϤā§āϰā§āĻāĻŋ āĻŦāĻžāϰā§āϤāĻž āĻĒā§āϰāĻĻāĻžāύ āĻāϰ⧠āĻĨāĻžāĻā§āĨ¤ āĻĒāϰāĻŦāϰā§āϤ⧠āĻĒā§āϰāĻĻāĻžāύ āϏā§āĻā§āĻāĻŽā§āύā§āĻā§ āĻĒā§āĻāĻāĻžāϰ āĻĒā§āϰā§āĻŦā§ āϏāĻžāĻŦ āĻ āĻĨāĻŦāĻž āĻĢāĻžāĻāĻļāύ āĻĨā§āĻā§ āĻāĻāĻāĻŋ āĻĒā§āϰā§āĻā§āϰāĻžāĻŽ āĻ āĻĒāϏāĻžāϰāĻŖ āύāĻŋāĻļā§āĻāĻŋāϤ āĻāϰāĻžāϰ āĻāύā§āϝ Exit Sub āĻ āĻĨāĻŦāĻž Exit Function āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰāĻž āĻšā§āĨ¤
āύāĻŋāĻā§āϰ āĻāĻĻāĻžāĻšāϰāĻŖāĻāĻŋ GoSub āĻāĻŦāĻ Return āĻāϰ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻŦā§āϝāĻžāĻā§āϝāĻž āĻāϰ⧠āĻĨāĻžāĻā§āĨ¤ āĻĒā§āϰā§āĻā§āϰāĻžāĻŽā§āϰ āĻāĻāĻāĻŋ āĻ āĻāĻļ āĻĻā§āĻāĻŦāĻžāϰ āĻāĻžāϞāĻžāύā§āϰ āĻŽāĻžāϧā§āϝāĻŽā§, āĻŦā§āϝāĻŦāĻšāĻžāϰāĻāĻžāϰ⧠āĻĻā§āĻŦāĻžāϰāĻž āϏāύā§āύāĻŋāĻŦā§āĻļāĻā§āϤ āĻĻā§āĻāĻāĻŋ āϏāĻāĻā§āϝāĻžāϰ āĻŦāϰā§āĻāĻŽā§āϞ āĻāĻŖāύāĻž āĻāϰāĻž āĻšā§āĨ¤
Sub ExampleGoSub
Dim iInputa As Single
Dim iInputb As Single
Dim iInputc As Single
iInputa = Int(InputBox("Enter the first number: ","NumberInput"))
iInputb = Int(InputBox("Enter the second number: ","NumberInput"))
iInputc=iInputa
GoSub SquareRoot
Print "The square root of";iInputa;" is";iInputc
iInputc=iInputb
GoSub SquareRoot
Print "The square root of";iInputb;" is";iInputc
Exit Sub
SquareRoot:
iInputc=sqr(iInputc)
Return
End Sub