How to Create a Complex Assignment Expression

Top  Previous  Next

An IF structure assigns a value to the Result variable based on the true/false evaluation of a single logical expression. There are two possible assignments. If the condition tested is true, one assignment is made, if not true (false), then the other assignment is made. Nesting IF structures allows for even more alternative assignments.

A CASE structure selectively assigns a value to the Result variable based on the evaluation of multiple OF expressions against the CASE expression. The CASE structure offers a less complicated (but less flexible) method for assigning alternative values. CASE structures may also be nested, and IF and CASE structures may be nested within each other.

 

Complex Expressions - IF

Use an IF structure to assign one of two values to the Result field depending on a condition. Nesting IF structures allows more complex alternative assignments.

To create an IF conditional formula (from the Application Tree):

1.

Press the Formulas button.

2.

Highlight a Formula type in the list, and press the Insert button. The Formula Editor dialog appears.

3.

In the Name field, type a name for the formula.

4.

Verify the Class field in the Formula Class drop list.

A formula class determines where in the generated source code its calculation is performed. Each Clarion procedure template has its own set of formula classes. For example, in the Form Template there is a class called "After Lookups" which tells the Application Generator to compute the formula after all lookups to secondary files are completed for the procedure.

5.

In the Description field, type a description of the formula.

6.

In the Result field, type the variable to which the result of the expression is assigned, or press the ellipsis (...) button to choose a variable from the Select Field dialog.

You can choose a local, module, or global variable, or a data dictionary field.

In the Statement dialog, enter a valid expression that you nees to test. For example, if the condition will be:

IF Date > TODAY( )

7.

Simply enter "Date > TODAY( )" in the Statement dialog.

8.

Press the IF..THEN button.

The IF structure appears in the Structure window.

9.

On the Statement line, enter the IF condition to evaluate.

You can type the expression, or you can use the Operators and Operands buttons to select expression components, or you can do both.

10.

Press the Check button to check your syntax.

11.

Press the Accept button to insert your expression into the structure.

12.

Highlight the line below the IF line in the Structure window.

This is where the "True" assignment expression goes.

13.

On the Statement line, enter the "True" assignment expression.

Again, you can type the expression, or you can use the Operators and Operands buttons to select expression components, or you can do both. If the IF condition is true, this expression is evaluated and the resulting value is assigned to the Result variable.

A "true" assignment expression is not required. If no assignment is entered, then no assignment is made.

14.

Press the Check button to check your syntax.

15.

Press the Accept button to enter your expression into the structure.

16.

Highlight the line below the ELSE line in the Structure window

This is where the "False" assignment expression goes.

17.

On the Statement line, insert the "False" assignment expression.

Again, you can type the expression, or you can use the Operators and Operands buttons to select expression components, or you can do both. If the IF condition is false, this expression is evaluated and the resulting value is assigned to the Result variable.

A "false" assignment expression is not required. If no assignment is entered, then no assignment is made.

18.

Press the Check button to check your syntax.

19.

Press the Accept button to insert your expression into the structure.

To add a nested control structure:

20.

Highlight one of the assignment lines in the Structure window.

21.

Press either the CASE..OF or IF..THEN button.

A new nested structure appears in the Structure window.

22.

Insert expressions on the appropriate lines as described above.

Again, you can type the expression, or you can use the Operators and Operands buttons to select expression components, or you can do both

23.

When your control structure is complete, press the OK buttons in the Conditionals, Formula Editor, and Formulas dialogs.

 

Complex Expressions - CASE

A CASE structure can be used to assign one of several values to the Result field depending on which OF expression is equal to the CASE expression.

To create a CASE conditional formula (from the Application Tree dialog):

1.

Press the Formulas button.

2.

Highlight a Formula type in the list, and press the Insert button. The Formula Editor dialog appears.

The Formula Editor dialog appears.

3.

In the Name field, type a name for the formula.

4.

Verify the Class type in the Formula Class drop list.

A formula class determines where in the generated source code its calculation is performed. Each Clarion procedure template has its own set of formula classes. For example, in the Form Template there is a class called "After Lookups" which tells the Application Generator to compute the formula after all lookups to secondary files are completed for the procedure.

5.

In the Description field, type a description of the formula.

6.

In the Result field, type the variable to which the result of the expression is assigned, or press the ellipsis (...) button to choose a variable from the Select Field dialog.

You can choose a local, module, or global variable, or a data dictionary field. This name appears in the Formulas dialog list.

7.

Enter a valid expression in the Statement entry field.

8.

Press the CASE..OF button.

The CASE structure appears in the Structure window.

9.

On the Statement line, enter the CASE expression that is compared to the multiple OF expressions.

You can type the expression, or you can use the Operators and Operands buttons to select expression components, or you can do both.

10.

Press the Check button to check your syntax.

11.

Press the Accept button to insert your expression into the structure.

12.

Highlight the OF line below the CASE line in the Structure window.

This is where the first OF comparison expression goes.

13.

On the Statement line, enter the OF comparison expression.

Again, you can type the expression, or you can use the Operators and Operands buttons to select expression components, or you can do both. At runtime, if the CASE expression equals this OF expression, then the subsequent assignment expression is evaluated and the resulting value is assigned to the Result variable.

14.

Press the Check button to check your syntax.

15.

Press the Accept button to insert your expression into the structure.

16.

Highlight the line below the OF line in the Structure window.

This is where the first OF assignment expression goes.

17.

On the Statement line, insert the OF assignment expression.

Again, you can type the expression, or you can use the Operators and Operands buttons to select expression components, or you can do both. At runtime, if the CASE expression equals the above OF expression, then this assignment expression is evaluated and the resulting value is assigned to the Result variable.

18.

Press the Check button to check your syntax.

19.

Press the Accept button to insert your expression into the structure.

To add additional OF statements:

20.

Highlight an OF line in the Structure window.

21.

Press the Case..OF button

22.

Insert your expressions in the same manner described above.

To add a nested control structure:

23.

Highlight an assignment line in the Structure window.

24.

Press either the CASE..OF or IF..THEN button

25.

Insert expressions on the appropriate lines following the instructions in the previous sections.

Again, you can type the expression, or you can use the Operators and Operands buttons to select expression components, or you can do both.

26.

When your control structure is complete, press the OK buttons in the Conditionals, Formula Editor, and Formulas dialogs.