How to Use Branches in Your Scripts
A Branch Action allows your script to execute different actions depending on the outcome of a test. To perform the test, Alpha Anywhere evaluates an expression (the "branch expression"), or checks the value in a control on the form. For example, if the value of the branch expression is "Boston", you might want your script to print a report for your Boston customers, while if the value of the branch expression is "New York", you might want your script to print a report for your New York customers.
The first step is to specify the "branch expression". This is either an Alpha Anywhere expression that evaluates to a character value, or the name of a control on the current form. Next, you specify the possible values that this expression can have. For example, if your branch expression is City, then this expression might have possible values of:
- New York
You also specify if there is to be a default action. The default action occurs if the branch expression does not evaluate to any of the specified values. Next, you give the Branch Action a unique name to identify it. For example branch1. Then, for each of the possible values that the branch expression can have, you specify an action. The action is either:
- Do nothing - set a Flag Variable to .T., or
- Play a script
If you choose the "Play a script" action, then you must specify the name of the script to play. When the script is executed, if the expression evaluates to the corresponding value, then this script is executed (and the corresponding flag variable is set to .T.). If you choose the "Do nothing - set a Flag Variable to .T." option, then the only thing that happens is that the corresponding flag variable is set to .T. In the above example, if the branch expression evaluates to Boston, and the Branch Action was called branch1, the corresponding flag variable is branch1_boston. If you specified a default action, then the corresponding flag variable is called branchname_else. For example, branch1_else.
Any action in your script that follows the Branch Action can be made conditional by clicking the Conditional check box. When you make an action conditional, you can specify that the condition should be based on a flag variable. When the script executes, the action will only be executed if the specified flag variable is equal to .T. For example, your script might define the following actions:
Branch Action (called br1 ) that sets the br1_boston and br1_new_york.
Print Report Action that prints a report for "Boston"
Print Report Action that prints a report for "New York".
You would specify that the second action was conditional based on the flag variable br1_boston, and you would specify that the third action was conditional based on the flag variable br1_new_york.