David De Kok
David De Kok

Reputation: 33

How to write this IF statement in a CASE in Progress 4GL?

I'm trying to give the user the opportunity to filter on an image. In my code I will receive a string like

ASSIGN img = "images\green.png". 

I think it would be best to write the following IF statement in a CASE, but I don't know how, since you can not use something like MATCHES or any other variable value in a CASE statement.

IF img MATCHES "*green*" THEN DO:
    MESSAGE "It's green!"
        VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
ELSE IF img MATCHES "*orange*" THEN DO:
    MESSAGE "It's orange!"
        VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
ELSE IF img MATCHES "*red*" THEN DO:
    MESSAGE "It's red!"
        VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.

So I obviously can't write it like this:

CASE img:
    WHEN MATCHES "*green*" THEN DO:
        MESSAGE "It's green!"
            VIEW-AS ALERT-BOX INFO BUTTONS OK.
    END.
    WHEN MATCHES "*orange*" THEN DO:
        MESSAGE "It's red!"
            VIEW-AS ALERT-BOX INFO BUTTONS OK.
    END
    WHEN MATCHES "*red*" THEN DO:
        MESSAGE "It's red!"
            VIEW-AS ALERT-BOX INFO BUTTONS OK.
    END.
END CASE.

Any ideas or do I just leave it at the IF statement?

Upvotes: 3

Views: 1853

Answers (1)

bupereira
bupereira

Reputation: 1498

There is a small trick here that we use to put expressions in case statements:

CASE TRUE:
     WHEN img MATCHES "*green*" THEN DO:
          MESSAGE "It's green!"
             VIEW-AS ALERT-BOX INFO BUTTONS OK.
     END.
     WHEN img MATCHES "*orange*" THEN DO:
          MESSAGE "It's orange!"
             VIEW-AS ALERT-BOX INFO BUTTONS OK.
     END.
     WHEN img MATCHES "*red*" THEN DO:
          MESSAGE "It's red!"
             VIEW-AS ALERT-BOX INFO BUTTONS OK.
     END.
     OTHERWISE DO:
          MESSAGE "It's something else!"
             VIEW-AS ALERT-BOX INFO BUTTONS OK.
     END.
END CASE.

Upvotes: 2

Related Questions