我目前正在编写两组非常相似的 if-else 语句。他们基本上比较三个下拉菜单,并确保用户没有放下两个匹配的偏好。例如:
cbo_fac1 - Kitchen
cbo_fac2 - Kitchen
cbo_fac3 - Lounge
这将返回一条错误消息,因为cbo_fac1和cbo_fac2匹配。但是有一个我正在努力实施的特殊情况。下拉案例之一是No preference。
cbo_fac1 - Kitchen
cbo_fac2 - No preference
cbo_fac3 - No preference
cbo_fac1 - No preference
cbo_fac2 - No preference
cbo_fac3 - No preference
任何情况下都不允许匹配任何偏好选择。我该如何实施呢?这是我到目前为止使用的代码:
If cbo_fac1.Value = cbo_fac2.Value Then
MsgBox ("Facilities preference 1 and facilities preference 2 cannot be the same. Please select another option for facilities preference 2, if you have none then select 'No preference'")
Exit Sub
End If
If cbo_fac1.Value = cbo_fac3.Value Then
MsgBox ("Facilities preference 1 and facilities preference 3 cannot be the same. Please select another option for facilities preference 3, if you have none then select 'No preference'")
Exit Sub
End If
If cbo_fac2.Value = cbo_fac3.Value Then
MsgBox ("Facilities preference 2 and facilities preference 3 cannot be the same. Please select another option for facilities preference 3, if you have none then select 'No preference'")
Exit Sub
End If