我有很多导致相同消息框警报的场景。 是否有比制作几个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