Ability to Control Flow

Flow Control is the ability to evaluate a "condition expression"; if the condition is satisfied, the program can perform a particular action. Multiple actions may be defined, with the execution of each dependent on a particular outcome of the "condition" test.

In order for BarTender to determine the best time to run your scripts during a print job and which database fields it will need to access, it examines the structure of your template(s) and does 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 data base field or share name being skipped during BarTender's test run of your scripts prior to starting your print job. If the condition evaluates differently during the print job, so that these references are now executed instead of being skipped, the script may fail. This possibility is avoided by Forcing Reference to Fields and Share Names.

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:

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:

If Field("price") > $100 Then

message = "Please call manager to double-check payment."

Else

message = "Process order normally."

End If

The above example sets the variable "message" differently depending on whether or not the price field in the current database is greater than $100.

Other Types of Flow Control

Other types of Flow Control statements are available in Visual Basic. Some "branch," like the If-Else statements discussed above, while others "loop." Follow this procedure for more details on flow control statements:

  1. From the Script Assistant or BarTender's main pull-down menu, select Help on Visual Basic Scripting.

  2. Click on Feature Information.

  3. Click on VB Script Features.

  4. Find the category Control flow.

  5. Click on the keywords for the flow control statements about which you are curious.