Ajuda del LibreOffice 25.2
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
Si el programa troba una expressió Return no precedida de GoSub, el LibreOffice Basic torna un missatge d'error. Utilitzeu Exit Sub o Exit Function per garantir que el programa deixa una Sub o Funció abans d'arribar a l'expressió Return següent.
A l'exemple següent es demostra l'ús de GoSub i Return. Amb l'execució d'una secció del programa dues vegades, el programa calcula l'arrel quadrada de dos nombres que introdueix l'usuari.
Sub ExampleGoSub
Dim iInputa As Single
Dim iInputb As Single
Dim iInputc As Single
    iInputa = Int(InputBox("Introduïu el primer nombre: ","NumberInput"))
    iInputb = Int(InputBox("Introduïu el segon nombre: ","NumberInput"))
    iInputc=iInputa
    GoSub SquareRoot
    Print "L'arrel quadrada de";iInputa;" és";iInputc
    iInputc=iInputb
    GoSub SquareRoot
    Print "L'arrel quadrada de";iInputb;" és";iInputc
    Exit Sub
SquareRoot:
    iInputc=sqr(iInputc)
    Return
End Sub