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özdizimi:


GoSub label[:]

Parametreler:

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
Uyarı Simgesi

Program GoSub den önce bir Return ifadesiyle karşılaşmazsa, LibreOffice Basic hata mesajı döndürür. Programın bir sonraki Return ifadesiyle karşılaşmasından önce Sub veya Fonksiyon'dan çıktığını garantilemek için Exit Sub veya Exit Function kullanın.


Aşağıdaki örnek GoSub ve Return kullanımlarını gösterecektir. Program bir bölümünü iki defa çalıştırarak kullanıcı tarafından girilen iki sayının kare kökünü hesaplayacaktır.

Örnek:


Sub ExampleGoSub
Dim iInputa As Single
Dim iInputb As Single
Dim iInputc As Single
    iInputa = Int(InputBox("İlk sayıyı giriniz: ","NumberInput"))
    iInputb = Int(InputBox("İkinci sayıyı giriniz: ","NumberInput"))
    iInputc=iInputa
    GoSub SquareRoot
    Print iInputa;" ifadesinin kare kökü";iInputc
    iInputc=iInputb
    GoSub SquareRoot
    Print iInputb;" ifadesinin kare kökü";iInputc
    Exit Sub
SquareRoot:
    iInputc=sqr(iInputc)
    Return
End Sub

Lütfen bizi destekleyin!