﻿ 'Case' Logic

# 'Case' Logic

'Case' logic is a more complex extension of the If/Then/Else logic discussed earlier.  The term 'Case' derives from the sentence "In CASE a certain value(s) is (are) THIS, then do this"

Case logic is especially useful for comparing multiple values, multiple combinations of values, and for determining values in a cascading fashion.

If/Then/Else statements contain  basically two result sections: the True part and the False part. It is 'linear' in structure, reading from left to right, "If this value is X, then do this, else do this.

'Case' logic allows many result sections. It is 'stacked' in structure, and reads from top to bottom. Example (read the commas as "then"):

Case
Combination 1, A action
Combination 2, B action
Combination 3, C action
etc.

'Combination' above refers to the choices made in a preceding <<*AskOptions*>> display. The combinations refer to the positions of the selections made. (Caveats: If the display was from an <<*AskOptions(radio)*...>> call, only one position, not combinations of positions, will be 'analyzed'. Ditto If the display was from an <<*AskOptional*. . .>> call.)

When multiple values are involved, multiple considerations must be handled. Here's how we do it.

The answer combination is always converted to a positional number. So, if five items are in the list of choices, and the user selects the second and fifth item, Pathagoras will 'see' the answer numerically as 2 and 5.

If all the choices must be present in order to trigger the case event (but others can be as well), just type the qualifying choices, separating multiple choices with commas.

If only the exact choices listed must be present to trigger the case event (and none others), enclose the choices within curly braces. (The choices themselves must still be separated by commas.)

If any one of the listed choices will trigger the case event, separate the choices with '/OR'.

When the first true value is reached, the line is processed and the routine ends.

The Case list can be endless.

Below is an example that demonstrates how the initial selection of items (in this example, salad fixings) can lead to a cascading of subsequent selections including the salad name and the utensils needed to consume the salad.

You can  copy and paste this example into a document and process it. Pathagoras will ask you the first question dealing with the salad's "ingredients". If the user selects a predesignated combination of ingredients, Pathagoras will automatically return the common name of the salad and the utensil commonly used to consume it. Otherwise, the AskOptions questions (the final entry in the Case list) are presented.

A reminder: the answers that Pathagoras is analyzing in the Case list are positional. "1,6" refer to the first and sixth positions in the ingredients list (celery and cream cheese). For <<*AskOptional*>> commands, a 'yes' answer is assigned a '1' value, a 'no' answer a '0' value.

Creating a Case Logic List.

1.Display the Logic Wizard (previous section).

2.Make all selections as before, but check the box in the middle of the screen that reads "Create Case Logic Block"

3.After you have created your first Case Logic item, click the Transfer button. The initial formula will be copied into the clipboard and the screen will close. Navigate to the position in the Ask Table where you want the Case Block to appear and click Paste (Ctrl-V).

4.Note: You can only create the structure for the case block, which will consist of the Case title, one (and only one) Case entry PLUS the Ask associated with the primary element selected at the right (this Ask must be the last entry, as it is the 'default item' if no prior Cases are true when document processing occurs).

5.You can (and should) add as many additional 'tests' as you wish, following the pattern shown in the transferred Case Logic Block.

6.If all selections must be met, enclose the selections within {curly braces}. Otherwise, the default 'one or more of the choices must match' will apply.'

Here is another, perhaps more 'practical' example. The clauses <<wil100>>, etc are clauses that shipped with the program. Therefore, you can copy and paste this example into a document and actually process it.