急求!!VB设计中的农夫过河问题,多个if语句并列叠加怎么编写代码??急求急求!!

If farmer.Value = 1 And cabbage.Value = 1 Then
MsgBox "你的狼吃了羊,羊没了。"
End If

If farmer.Value = 1 And wolf.Value = 1 Then
MsgBox "你的羊吃了白菜,白菜没了。"
End If

If farmer.Value = 1 And wolf.Value = 1 And sheep.Value = 1 Then
MsgBox "选中3种以上(含3种)对象过河"
End If

If farmer.Value = 1 And wolf.Value = 1 And cabbage.Value = 1 Then
MsgBox "选中3种以上(含3种)对象过河"
End If

If farmer.Value = 1 And cabbage.Value = 1 And sheep.Value = 1 Then
MsgBox "选中3种以上(含3种)对象过河"
End If

If wolf.Value = 1 And cabbage.Value = 1 And sheep.Value = 1 Then
MsgBox "选中3种以上(含3种)对象过河"
End If

If farmer.Value = 1 And wolf.Value = 1 And cabbage.Value = 1 And sheep.Value = 1 Then
MsgBox "选中3种以上(含3种)对象过河"
End If

只会写了单个的代码,运行后跳出好多个对话框···怎么把他们给组合起来编写代码?

条件1:If farmer.Value = 1 And cabbage.Value = 1 Then包含在条件7:If farmer.Value = 1 And wolf.Value = 1 And cabbage.Value = 1 And sheep.Value = 1 Then 中,发生条件7时,条件1语句也运行了,所以出现多个对话框
解决:
if(farmer.Value +wolf.Value+cabbage.Value +sheep.Value )<3 then
If farmer.Value = 1 And cabbage.Value = 1 Then
MsgBox "你的狼吃了羊,羊没了。"
End If
If farmer.Value = 1 And wolf.Value = 1 Then
MsgBox "你的羊吃了白菜,白菜没了。"
End If
elseif then
MsgBox "选中3种以上(含3种)对象过河"
End If
温馨提示:答案为网友推荐,仅供参考
相似回答