GoSub...Return instrukzioa

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.

Sintaxia:


GoSub label[:]

Parametroak:

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
      ' instrukzioak
      GoSub label
      ' instrukzioak
      Exit Sub/Function
  label:
      ' instrukzioak
      Return
  End Sub/Function
Abisu-ikonoa

Programak Return instrukzioa aurkitzen badu aurretik GoSub gabe, LibreOffice Basic-ek errore-mezua itzuliko du. Hurrengo Return instrukziora iritsi aurretik programak azpierrutina edo funtzio bat utzi duela ziurtatzeko, erabili Exit Sub edo Exit Function.


Ondorengo adibidean GoSub eta Return instrukzioen erabilera erakusten da. Programaren atal bat bi aldiz exekutatzean, programak erabiltzaileak sartutako bi zenbakiren erro karratua kalkulatzen du.

Adibidea:


Sub ExampleGoSub
Dim iInputa As Single
Dim iInputb As Single
Dim iInputc As Single
    iSarreraa = Int(InputBox("Sartu lehen zenbakia: ","Sarrerako zenbakia"))
    iSarrerab = Int(InputBox("Sartu bigarren zenbakia: ","Sarrerako zenbakia"))
    iInputc=iInputa
    GoSub SquareRoot
    Print iSarreraa; "(r)en erro karratua honakoa da: ";iSarrerac
    iInputc=iInputb
    GoSub SquareRoot
    Print iSarrerab;"(r)en erro karratua honakoa da: ";iSarrerac
    Exit Sub
SquareRoot:
    iInputc=sqr(iInputc)
    Return
End Sub

Emaguzu laguntza!