Conteníu
Índiz 🔎︎

# GoSub...Return Statement

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.

### Syntax:

    GoSub label[:]

### Parameters:

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'l programa atopa una instrucción Return que nun va precedida de GoSub, LibreOffice Basic devuelve un mensaxe de fallu. Use Exit Sub o Exit Function p'asegurase de que'l programa sala d'una Sub o Function enantes de llegar a la siguiente instrucción Return.

L'exemplu siguiente demuestra l'usu de GoSub y Return. Al executar una seición de programa dos vegaes, ésti calcula'l raigañu cuadráu de dos númberos qu'introdució l'usuariu.

### Example:

    Sub ExampleGoSub
    Dim iInputa As Single
    Dim iInputb As Single
    Dim iInputc As Single
        iInputa = Int(InputBox("Escriba'l primer númberu: ","EntradaNúmberu"))
        iInputb = Int(InputBox("Escriba'l segundu númberu: ","EntradaNúmberu"))
        iInputc=iInputa
        GoSub SquareRoot
        Print "La raíz cuadrada de";iInputa;" ye";iInputc
        iInputc=iInputb
        GoSub SquareRoot
        Print "La raíz cuadrada de";iInputb;" ye";iInputc
        Exit Sub
    SquareRoot:
        iInputc=sqr(iInputc)
        Return
    End Sub

Temes rellacionaes

GoTo Statement

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