Isi

# 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.

### Sintaksis:

    GoSub label[:]

### Parameter:

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

Jika program menemukan pernyataan Pengembalian yang tidak didahului oleh Pergi ke Sub, LibreOffice Dasar mengembalikan pesan kesalahan. Gunakan Keluar Sub atau Fungsi Keluar untuk memastikan bahwa program meninggalkan Sub atau Fungsi sebelum mencapai pernyataan Pengembalian berikutnya.

Contoh berikut menunjukkan penggunaan Pergi ke Sub dan Pengembalian. Dengan menjalankan bagian program dua kali, program menghitung akar kuadrat dari dua angka yang dimasukkan oleh pengguna.

### Contoh:

    Sub ExampleGoSub
    Dim iInputa As Single
    Dim iInputb As Single
    Dim iInputc As Single
        iInputa = Int(InputBox("Masukkan nomor pertama: ","NumberInput"))
        iInputb = Int(InputBox("Masukkan nomor kedua: ","NumberInput"))
        iInputc=iInputa
        GoSub SquareRoot
        Cetak "Akar kuadrat dari";iInputa;" adalah";iInputc
        iInputc=iInputb
        GoSub SquareRoot
        Cetak "Akar kuadrat dari";iInputb;" adalah";iInputc
        Exit Sub
    SquareRoot:
        iInputc=sqr(iInputc)
        Return
    End Sub

Topik Terkait

GoTo Statement

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