Example 3 - Using Nested if Instructions

This example shows how to add another condition for which to test to your script code. This example tests for sales greater than $8000 but prints a warning message only if the sales item is a destination vacation; that is, it has a sales code of DEST.

For details about creating the first if condition, see steps 1 through 9 in Example 1, earlier in this appendix.

The following image shows the first if condition, where the comparison figure is 8000 in the current example.

You then apply the second condition.

To add the second condition

  1. Click in the line below the current if instruction.

  2. Select (double-click) the if then command in the Commands folder of the Commands list box.

    Another set of if instruction and its then and endif clauses are then inserted, as shown in the following image.

  3. Click between the second-level if instruction and the then clause.

  4. From the Fields list box, select (double-click) the field on which you are going to test your second-level condition.

    In this example, another report field is selected, as shown in the following image.

    In this example, this field is to be compared to the "DEST" literal value, which is the sales code prefix for destination vacation sales items. The following image shows the field after it has been selected.

  5. Select (double-click) the equals sign (=) from the Comparison operators folder in the Commands list box (or simply type it).

  6. Enter the literal value with which you want to compare the sales code prefix, as shown in the following image.

  7. Assign your literal message to your result.

    Type the result := variable declaration below the second if instruction, or cut and paste the line from lower in your code, as shown in the following image.

    The script code is then complete, but it is good practice to tidy up your code indentations in order to outline the logic.

  8. It is good coding practice to indent the second if instruction, as it is executed only if the first if condition is satisfied. Similarly, the result line should be indented again, as it is executed only if both if conditions are satisfied.

    Finally, lining up both endif clauses so that they match their respective if instructions makes the structure of you code clearer, as shown in the following image.

  9. To check your script for errors, click the Save button as you did in Example 1, earlier in this appendix.

When this script field is applied to the report, sales items for destination vacations that have a price greater than $8,000 have the warning message displayed, as shown in the following image.