如何在 CASE in Progress 4GL 中编写此 IF 语句?
How to write this IF statement in a CASE in Progress 4GL?
我试图让用户有机会过滤图像。在我的代码中,我会收到一个像
这样的字符串
ASSIGN img = "images\green.png".
我认为最好在 CASE 中编写以下 IF 语句,但我不知道该怎么做,因为您不能在 CASE 语句中使用 MATCHES 或任何其他变量值。
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.
所以我显然不能这样写:
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.
有什么想法,还是我只是将其留在 IF 语句中?
这里有一个小技巧,我们用来将表达式放在case语句中:
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.
我试图让用户有机会过滤图像。在我的代码中,我会收到一个像
这样的字符串ASSIGN img = "images\green.png".
我认为最好在 CASE 中编写以下 IF 语句,但我不知道该怎么做,因为您不能在 CASE 语句中使用 MATCHES 或任何其他变量值。
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.
所以我显然不能这样写:
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.
有什么想法,还是我只是将其留在 IF 语句中?
这里有一个小技巧,我们用来将表达式放在case语句中:
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.