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
រូប​តំណាង​ព្រមាន

ប្រសិន​បើ​​កម្មវិធី​ជួប​ប្រទះ​សេចក្តី​ថ្លែង​ការណ៍ Return ដែល​មិន​នៅ​ពី​មុខ​ដោយ GoSub LibreOfficeDev Basic ត្រឡប់​សារ​កំហុស​មួយ ។ ប្រើ Exit Sub ឬ​Exit Function ដើម្បី​ធ្វើ​ឲ្យ​ប្រាកដ​ថា​កម្មវិធី​ចាកចេញ​ពី Sub ឬ​ Function មុន​ពេល​ទៅ​ដល់​សេចក្តី​ថ្លែង​ការណ៍ Return បន្ទាប់ ។


ឧទាហរណ៍​ដូច​ខាង​ក្រោម​បង្ហាញ​ពី​ការ​ប្រើ​នៃ GoSub និងReturn ។ ដោយ​ប្រតិបត្តិ​ផ្នែក​នៃ​កម្មវិធី​ពីរ​ដង កម្មវិធី​គណនា​ឫស​ការេ​នៃ​ចំនួន​ពីរ​ដែល​ត្រូវ​បាន​បញ្ចូល​ដោយ​អ្នក​ប្រើ ។

Example:


Sub ExampleGoSub
Dim iInputa As Single
Dim iInputb As Single
Dim iInputc As Single
    iInputa = Int(InputBox("Enter the first number: ","NumberInput"))
    iInputb = Int(InputBox("Enter the second number: ","NumberInput"))
    iInputc=iInputa
    GoSub SquareRoot
    Print "The square root of";iInputa;" is";iInputc
    iInputc=iInputb
    GoSub SquareRoot
    Print "The square root of";iInputb;" is";iInputc
    Exit Sub
SquareRoot:
    iInputc=sqr(iInputc)
    Return
End Sub