case
FORMULA

The case statement allows multiple decisions to be chained together (also see the elseif statement).


Parameters

This statement has one parameter:

formula – is a formula that decides whether or not to execute the following statements. The result of this formula must be a Boolean (true/false) value.


Description

The case statement is designed to be used in groups. Each group begins with a case statement and ends with an endcase statement, there may be multiple case statements in between. There may also be a single defaultcase statement after the last case statement and before the endcase statement. The general arrangement should look something like this:

case (is formula 1 true?)
    perform option 1
case (is formula 2 true?)
    perform option 2
case (is formula 3 true?)
    perform option 3
endcase

When Panorama is running a procedure and encounters a group of case statements, it starts from the top of the group and checks whether or not the first formula is true. If not, it skips to the next case statement, continuing until it finds a true formula (if any). When it finds a true formula, it executes the statements after the case statement, continuing up until the next case statement, or until a defaultcase or endcase statement. It then jumps past the endcase statement and continues executing statements from there.

If none of the case formulas is true, Panorama will jump past the endcase statement and continues executing statements from there. Or, if there is a defaultcase statement, Panorama will jump to that.

If more than one case formula is true, only the first one encountered will be executed. In fact, once Panorama finds a true formula, it skips all of the other case statements in the group.

This example assigns a dollar amount to the field Rate based on the chosen shipper.

case Shipby = "UPS Ground"
    Rate = 5.00
case Shipby = "UPS Blue"
    Rate = 7.50
case Shipby = "UPS Red"
    Rate = 10.00
case Shipby = "Fed-ex standard"
    Rate = 12.00
case Shipby = "Fed-ex overnight"
    Rate = 18.00
case Shipby = "Fed-ex overnight Saturday"
    Rate = 25.00
defaultcase
    Rate = 4.50
endcase

The next example illustrates the possibility of multiple true formulas. If Sales is 650, all three of these formulas will be true. However, the award will be Gold since this is the first true formula. Since the first case is true, the following cases (Silver and Bronze) are all skipped.

case Sales > 500
    award = "Gold"
case Sales > 250
    award = "Silver"
case Sales > 100
    award = "Bronze"
endcase

It’s important to get the order right. In the following example, it would be impossible to get Gold or Silver awards.

case Sales > 100
    award = "Bronze"
case Sales > 250
    award = "Silver"
case Sales > 500
    award = "Gold"
endcase

Case vs. If/ElseIf

An alternative to a group of case statements is to use the if, elseif, else and endif statements. Here’s the first example above rewritten to use these statements.

if Shipby = "UPS Ground"
    Rate = 5.00
elseif Shipby = "UPS Blue"
    Rate = 7.50
elseif Shipby = "UPS Red"
    Rate = 10.00
elseif Shipby = "Fed-ex standard"
    Rate = 12.00
elseif Shipby = "Fed-ex overnight"
    Rate = 18.00
elseif Shipby = "Fed-ex overnight Saturday"
    Rate = 25.00
else
    Rate = 4.50
endif

An advantage to using if/elseif/endif is that these statements can be nested – case statements cannot be nested. Here this example has been rewritten to group each shipping company into a group.

if Shipby beginswith "UPS"
    if Shipby endswith "Red"
        Rate = 10.00
    elseif Shipby = "UPS Blue"
        Rate = 7.50
    else
        Rate = 5.00
    endif
elseif Shipby beginswith "Fed-ex"
    if Shipby endswith "Saturday"
        Rate = 25.00
    elseif Shipby endswith "overnight"
        Rate = 18.00
    else
        Rate = 12.00
    endif
else
    Rate = 4.50
endif

In this particular example it’s probably better not to nest the options, but in some cases this can be much clearer.


See Also


History

VersionStatusNotes
10.0UpdatedCarried over from Panorama 6.0, but no longer limited to 75 case statements per group.