LOTUSSCRIPT LANGUAGE


Conditional control transfer with the On...GoTo statement
The branching statement On...GoTo transfers control conditionally.

The syntax is:

On expression GoTo label, [ , label ]...

The statement transfers control to a target label depending on the value of expression: It transfers control to the first label if expression is 1, to the second label if expression is 2, and so on.

On...GoTo and its target labeled statements must be in the same procedure. The flow of control is determined at run time.

The following sub uses On...GoTo to run one of two simple LotusScript performance tests. By typing 1 or 2 into an input box, the user chooses whether to time 1000 iterations of a Do loop, or count the number of Yield statements executed in one second. Using On...GoTo, the script branches to run one test or the other and prints the result.

Sub RunPerfTest
  Dim directTempV As Variant, directTest As Integer, _
    i As Integer
  Dim startTime As Single
SpecTest: directTempV = InputBox$(|Type 1 for iteration
     time, or 2 for # of yields:|)
  If Not IsNumeric(directTempV) Then Beep : GoTo SpecTest
  directTest% = CInt(directTempV)
  If directTest% < 1 Or directTest% > 2 _
     Then Beep : GoTo SpecTest
  i% = 0
  ' Branch on 1 or 2.
  On directTest% GoTo TimeCheck, ItersCheck
TimeCheck: startTime! = Timer()
  Do While i% <= 1000
     i% = i% + 1
  Loop
  Print "Time in seconds for 1000 iterations: " _
      Timer() - startTime!
  Exit Sub
ItersCheck: startTime! = Timer()
  Do
     Yield
     i% = i% + 1
  Loop While Timer() < startTime! + 1
  Print "Number of Yields in 1 second: " i%
End Sub
Call RunPerfTest()

Three runs of the sub RunPerfTest might have these results, depending on the speed of the computer where LotusScript is running:

' Output:
' (With input 2)  Number of Yields in 1 second:  975
' (With input 1)  Time in seconds for 1000 iterations:  .109375
' (With input 2)  Number of Yields in 1 second:  952

See Also