Example 2 - Using the if Instruction and its then and else Clauses
In Example 1 earlier in this appendix, a message is printed if a sales value is greater than one million dollars. For all sales values that are a million dollars or less, no action is taken and the JADE Report Writer applies a default null value to the result.
However, if you want to apply a message that highlights the sales values that are within reasonable limits (that is, not greater than one million dollars), you need to code an else clause for the if instruction.
To return a result when the if instruction is not satisfied
-
Perform the steps documented in Example 1, earlier in this appendix, except that you double-click the if then else command in the Commands folder of the Commands list box in step 3.
The if instruction and its then, else, and endif clauses are then inserted, as shown in the following image.
-
Follow steps 4 through 11 of Example 1 to enter the code that sets the result when the sales value is more than one million dollars. Make sure that you insert your code for the if instruction and then clause before the else clause.
It is also good practice to indent the else clause so that it lines up with the start of the if instruction, as shown in the following image.
-
Enter another result := variable declaration after the else clause.
Type it or copy and paste it from the previous line, as shown in the following image.
-
Enter your message as a string literal; that is, enter it between quotation marks, as shown in the following image.
-
To check your script for errors, click the Save button as you did in Example 1, earlier in this appendix.
When you apply the script that includes this code to your report, the warning message is printed for sales values of more than one million dollars. For values less than one million dollars (provided by the else clause), an "OK" message is printed, as shown in the following report extract.
Make sure that you have entered a semicolon character (;) at the end of your instructions.
See "Resolving Errors in Scripts", later in this appendix, for a description of any errors that you may encounter.