Flow Control

When you run a script, execution starts with the Sub Main statement and continues line-by-line until the End Sub statement at the end of the main procedure or until an End statement is encountered. SEveral flow control statements allow you to change this line-by-line progression according to conditions encountered by your script. The Scripter BASIC language includes a variety of looping and branching statements that is typical for modern programming languages. The flow control statements include the following (see the online BASIC language help for details on the syntax of these statements):

IF...END IF

IF...END IF executes a statement only if a condition is true.

IF...ELSE...END IF

The alternate of IF...END IF form executes one statement if a condition is true and a different statement if the condition is false.

SELECT CASE...END SELECT

SELECT CASE...END SELECT branches to one of several statements. This compares the value of an expression to several test values and executes the statements associated with the test value that matches the expression value.

DO...LOOP

DO...LOOP is the basic looping statement. This statement loops either while a condition is true or until a condition becomes true and tests the condition either at the top of the loop or at the bottom of the loop.

This and all other loop structures may be stopped before the test condition has been met by placing an Exit statement in the body of the loop.

WHILE...WEND

WHILE...WEND loops while a condition is true and tests the condition at the top of the loop.

FOR...NEXT

FOR...NEXT loops a number of times and increments (or decrements) an index variable each time through the loop.

FOR EACH...NEXT

FOR EACH...NEXT iterates through all the elements in a collection object. Several Surfer automation objects are collection objects. The For...Each statement is a convenient way to process each element of a collection.

For example, the following code fragment closes all the documents in the Surfer Documents collection object:

'Assume that several documents are already open and that "SurferApp"

' is the name of a variable which refers to the Surfer Application object

Dim documents, doc As Object

Set documents = SurferApp.Documents

For Each doc In documents

doc.Close

Next