我有很多導致相同消息框警報的場景。 是否有比製作幾個if語句更容易/更好的解決方案?更改IF語句以提高效率
PRODUCTS BOX1 BOX2 BOX3
--------------------------------------------------
|Apples, Oranges, | X | x | |
|Grapes, Peaches | x | x | |
|------------------------------------------------|
|Wheat | x | x | x |
|-------------------------------------------------
|Peanuts | | x | |
--------------------------------------------------
If product = "Apples" or product = Oranges or product = Grapes or products = Peaches then
If box = "box1" or box = "box2" then
msgbox "Your box may require approval"
End If
End If
If product = "Wheat" then
If box = "box1" or box = "box2" or box = "box3" then
msgbox "Your box may require approval"
End If
End If
If product = "Peanuts" then
If box = "box2" then
msgbox "Your box may require approval"
End If
End If
如果你的代碼按預期工作,而你正在尋找更好的方法做同樣的事情,然後再考慮你的描述真實*,實際的工作*代碼在[codereview.se]上。 (注意:假設/僞代碼不會飛過) –
查看Select Case語句。組織起來可能更容易。至少,按照Doug的建議,將msgbox()放入子程序中。 – B540Glenn