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.

When BarTender determines the best time to run your scripts during a print job and which database fields it needs to access, it examines the structure of your templates and performs an invisible test run of your scripts. Among other factors, BarTender considers when and how any database fields and shared data sources are used.

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.

Using If and Else Statements

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

Other types of flow control statements are available in Visual Basic. Some "branch," such as the If and Else statements, while others "loop."

ClosedTo view more details about flow control statements

  1. In the Script Editor, click Help, and then click VBScript Language Reference.

  2. In the left navigation pane of the VBScript help system, click to expand the Language Reference book. Alternatively, in the Visual Basic Scripting Edition pane, click Feature Information under VBScript Language Reference.

  3. Click VBScript Features.

  4. In the VBScript Features list, locate the Control flow category.

  5. Click the keywords for the flow control statements that you want.

Related Topics