How to write CASE-Statement in Progress-4GL?

Posted by LegacyUser on 15-Jan-2006 09:46

Hi,

how can you write this IF-Statement as a CASE-Statement?

DEF VAR i AS INT.

IF i < 0 THEN

MESSAGE "i < 0".

ELSE IF i = 0 THEN

MESSAGE "i = 0".

ELSE

MESSAGE "i > 0".

like following?? It doesn't work!!

CASE i:

WHEN < 0 THEN

MESSAGE "i < 0".

WHEN = 0 THEN

MESSAGE "i = 0".

WHEN > 0 THEN

MESSAGE "i > 0".

END CASE.

DISP i.

Thanks

Tom

All Replies

Posted by LegacyUser on 28-Feb-2006 13:33

your code doesn't work, beacuse you difine case i ( i like int) and when

The value in when instruction must be the same type like the case value:

Posted by LegacyUser on 05-Apr-2006 13:17

Case MUST be constant value, therefore value will NOT work, how can the compiler compile the result if the value is not known?

CORRECT use would be;

CASE cVar:

WHEN 'SomeValue' THEN

DO:

/* block here */

END. /* SomeValue */

WHEN 'AnotherValue' THEN

DO:

/* block here */

END. /* AnotherValue */

END CASE. /* cVar */

Posted by LegacyUser on 05-Apr-2006 13:48

CASE cVar:

The principal is the same for other datatypes. EG when wishing to case an integer

CASE iVar

WHEN inValue THEN /* eg WHEN 10 THEN*/

DO:

/* block here */

END. /* SomeValue */

WHEN DIFFERENTinValue THEN /* eg WHEN 23 THEN*/

DO:

/* block here */

END. /* AnotherValue */

END CASE. /* iVar */

This thread is closed