Ability to Control Flow

Flow Control is the ability to evaluate a "conditional expression". If a condition is satisfied, the program will perform a particular action. Multiple actions may be defined, with the execution of each action 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 database 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 and these references are executed instead of being skipped (as in the test run), the script may fail. This possibility is avoided 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:

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.

For 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 VB. Some "branch," like the If-Else statements discussed above, while others "loop."

ClosedTo view more details on control flow statements

  1. From the Script Editor, select Help > VBScript Language Reference.

  2. Click on Feature Information.

  3. Click on VBScript Features.

  4. Find the category Control flow.

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

Related Topics