我试图让用户有机会过滤图像。在我的代码中,我将收到一个像
这样的字符串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声明中?
答案 0 :(得分:2)
这里有一个小技巧,我们用它来将表达式放在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.