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.

SĂŒntaks:


GoSub label[:]

Parameetrid:

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
      ' laused
      GoSub label
      ' laused
      Exit Sub/Function
  label:
      ' laused
      Return
  End Sub/Function
Hoiatav ikoon

Kui programm jÔuab Return-lauseni, millele ei eelne lauset GoSub, siis tagastab LibreOffice Basic veateate. Selleks, et programm sulgeks enne jÀrgmise Return-lauseni jÔudmist alamprotseduuri vÔi funktsiooni, kasuta lauset Exit Sub vÔi Exit Function.


JÀrgmine nÀide on lausete GoSub ja Return kasutamise kohta. Programmiosa kaks korda kÀivitamisel arvutab programm kasutaja sisestatud kahe arvu ruutjuure.

NĂ€ide:


Sub ExampleGoSub
Dim iInputa As Single
Dim iInputb As Single
Dim iInputc As Single
    iInputa = Int(InputBox("Sisesta esimene arv: ","ArvuSisestus"))
    iInputb = Int(InputBox("Sisesta teine arv: ","ArvuSisestus"))
    iInputc=iInputa
    GoSub SquareRoot
    Print "Ruutjuur arvust";iInputa;" on";iInputc
    iInputc=iInputb
    GoSub SquareRoot
    Print "Ruutjuur arvust";iInputb;" on";iInputc
    Exit Sub
SquareRoot:
    iInputc=sqr(iInputc)
    Return
End Sub

Palun toeta meid!