amitsdotcom
28th November 2010, 08:09
Hello, I am trying to use the CASE Expression however am always getting an error stating CASE not expected.

There is no clear example in the programming guide, can anybody please assist in getting a proper sytax of using the CASE Expression

mohdusman
28th November 2010, 10:19
Please see the sample as below

on case ctr
case 1:
month = "First"
break
case 2:
month = "Second"
break
endcase

bdittmar
28th November 2010, 12:20
Hello, I am trying to use the CASE Expression however am always getting an error stating CASE not expected.

There is no clear example in the programming guide, can anybody please assist in getting a proper sytax of using the CASE Expression

Hello,

what's not clear in progguide?

The ON CASE statement
This statement has the following syntax:

ON CASE expression
CASE expr_1:
statements_1
break
CASE expr_2:
statements_2
break
CASE expr_3:
statements_3
break
DEFAULT: | optional
statements
ENDCASE
The ON CASE statement is a multiple-way decision table. It evaluates an expression and compares the result with the expressions of each specified CASE. When a match is found, control transfers to that branch and the code for that particular CASE is executed. If no match is found, the DEFAULT code is executed. If there is no DEFAULT label, the program continues with the first statement after ENDCASE. CASES and the DEFAULT label can occur in any order.

The CASE statements serve as labels. This means that after execution of the statements related to a particular CASE, the remaining CASES continue to be evaluated. However, if two CASE expressions give the same result, only the first is executed.

You can use the BREAK command to skip evaluation of other CASES after the code for the matching CASE has been executed. You include this command at the end of the code for each CASE. When the command is executed, execution of the ON CASE statement ends. In the case of nested CASES, the BREAK command cancels execution of the CASE statements at the same level only.

The ON CASE expression must be either a Long expressions (ON CASE) or a String expressions (ON CASE).

Regards

amitsdotcom
29th November 2010, 05:29
Thank you for the assistance, actually i was referring to case expression in programming and not the on case, hence could not get to understand it.

I thank you all for your guiding me through the correct syntax...