Ability to Control Flow |
Flow control is the ability to evaluate a conditional expression. If a condition is satisfied, the program performs a particular action. You can specify multiple actions, and the running of each action depends on a particular outcome of the condition test.
Depending on your flow control statements, it is possible to set up a conditional expression that results in code that references a database field or share name being skipped during the test run of your scripts before your print job starts. If the condition evaluates differently during the print job and these references are run instead of being skipped (as in the test run), the script might fail. You can avoid this possibility by forcing a reference to the database field or named data source.
The simplest flow control in Visual Basic is done with If and Else statements. If and Else statements can be used to program statements such as the following:
If the price is greater than $100, then perform a function, computation, or other task. Otherwise, perform a different function, computation, or task.
Using If and Else statements, we can program this in Visual Basic, as follows:
If Field("price") > $100 Then
message = "Please call manager to double-check payment."
Else
message = "Process order as usual."
End If
This example sets the "message" variable differently depending on whether the price field in the current database is greater than $100.
For information about an alternative to using If
and Else
statements, refer to Using the In-line If (IIF) Function.
Other types of flow control statements are available in Visual Basic. Some "branch," such as the If and Else statements, while others "loop."
To view more details about flow control statements
Related Topics