Using Control Structures

Setup Factory provides several actions that you can use to build control structures into your installer: IF, END IF, WHILE, END WHILE, Label, GOTO Label, and Abort.

IF and END IF

The IF action begins what's known as a conditional block. A conditional block is simply a series of actions that will only be performed if a condition is met. In this case, the condition is an expression entered on the Action Properties dialog for the IF action itself.

Each IF action must be paired with an END IF action. The END IF action marks the end of the conditional block begun by the corresponding IF action.

A conditional block is therefore defined as the series of actions between an IF action and the corresponding END IF action.

Here's an example of a simple conditional block:

NOTE

 

The actions in a conditional block are usually indented to help set them apart visually from other actions.

If an IF action's condition evaluates to a true result, all of the actions between the IF action and the next corresponding END IF action are performed. If an IF action's condition evaluates to a false result, the conditional block is "skipped," and the next action after the END IF action is performed.

For instance, in the preceding example, the message "The value of the variable is five!" would only be shown if the value in the variable %VariableBeingTested% was 5.

Conditional blocks can be nested, which is to say that you may begin and end one conditional block within another.

 For example:

In this example, the first IF action matches up with the last END IF action, and the second IF action matches up with the first END IF action. The second IF action that tests %FavoriteSong% to see if it contains the string "PenniesFromHeaven" would only be performed if %FavoriteMusic% contained the string "Jazz".

WHILE and END WHILE

The WHILE action begins what's known as a while loop. A while loop is simply a series of actions that will be performed repeatedly for as long as a condition is met. In this case, the condition is an expression entered on the Action Properties dialog for the WHILE action itself.

Each WHILE action must be paired with an END WHILE action. The END WHILE action marks the end of the loop begun by the corresponding WHILE action.

A while loop is therefore defined as the series of actions between a WHILE action and the corresponding END WHILE action.

Here's an example of a short while loop:

NOTE

 

The actions in a while loop are usually indented to help set them apart visually from other actions.

If a WHILE action's condition evaluates to a true result, all of the actions between the WHILE action and the next corresponding END WHILE action are performed. When the END WHILE action is reached, Setup Factory goes back to the corresponding WHILE action and evaluates its condition again. The actions between the WHILE and the corresponding END WHILE continue to "loop" in this fashion until the WHILE action's condition evaluates to a false result. When that happens, the actions in the while loop are "skipped," and the next action after the END WHILE action is performed.

For instance, in the preceding example, the while loop would be performed repeatedly for as long as the value in the variable %counter% was less than 5. Since %counter% is set to 1 before the while loop and incremented by 1 before the END WHILE action, this while loop would be performed four times. The result of the loop would be four directories created in %AppDir%, named:

Folder 1
Folder 2
Folder 3
Folder 4

NOTE

 

Each trip through a while loop is called an "iteration."

Like conditional blocks, while loops can also be nested, which is to say that you may begin and end one loop within another. For example:

In this example, the inner loop would be performed 5 times during each trip through the outer loop. At the end of the last iteration through the outer while loop, the variable %a% would equal 100.

Label and GOTO Label

The Label action is used to assign a name to a specific line in an action list. This name or "label" can then be used as the destination for a GOTO Label action.

The GOTO Label action can be used to "jump" directly to the line occupied by a specific label in the same action list. You can use a GOTO label action to "skip" over other actions. For example:

In this example, the Show Message Box action will never be performed, because the GOTO Label action causes Setup Factory to jump directly to the label named "Target".

Although GOTO Label actions have no intelligence of their own, you can place them in conditional blocks to make jumps that are only performed when certain conditions are met. For example:

In this example, the GOTO Label action is only performed if the user's system is connected to the Internet.

Abort

The Abort action immediately aborts the installation process and exits the installer. This has a similar effect to the user pressing the Cancel button. (The Cancel button asks the user to confirm before exiting; the Abort action doesn't ask, but instead just exits immediately.)

An example of where you might want to use an Abort action is in a custom error handler, after an irrecoverable error has been encountered.

 

See Also: Alphabetical List of Actions, Categorical List of Actions