您好我正在为学校项目编写二十一点游戏。但我遇到了一个错误。当我运行我的程序代码时,'ElseIf'前面必须有匹配的'If'或“ElsIf”。我已经尝试了很多不同的安排,但我无法弄明白。下面是我的Msgbox代码。
请帮助
Dim responseYouWon = MsgBox(youWonMsg, style, youWonTitle)
Dim responseYouLost = MsgBox(youLostMsg, style, youLostTitle)
Dim responseYouDrew = MsgBox(youDrewMsg, style, youDrewTitle)
If PlayerSum < 21 And PlayerSum > ComputerSum Then
If responseYouWon = MsgBoxResult.Yes Then
btnPlayAgain.PerformClick()
Else
btnQuit.PerformClick()
End If
End If
ElseIf ComputerSum > 21 And PlayerSum < 21 Then
If responseYouWon = MsgBoxResult.Yes Then
btnPlayAgain.PerformClick()
Else
btnQuit.PerformClick()
End If
ElseIf ComputerSum > 21 And ComputerSum < 21 Then
If responseYouWon = MsgBoxResult.Yes Then
btnPlayAgain.PerformClick()
Else
btnQuit.PerformClick()
End If
ElseIf PlayerSum = 21 And ComputerSum > 21 Then
If responseYouWon = MsgBoxResult.Yes Then
btnPlayAgain.PerformClick()
Else
btnQuit.PerformClick()
End If
ElseIf PlayerSum = 21 And ComputerSum < 21 Then
If responseYouWon = MsgBoxResult.Yes Then
btnPlayAgain.PerformClick()
Else
btnQuit.PerformClick()
End If
ElseIf ComputerSum < 21 And ComputerSum > PlayerSum Then
If responseYouLost = MsgBoxResult.Yes Then
btnPlayAgain.PerformClick()
Else
btnQuit.PerformClick()
End If
ElseIf PlayerSum > 21 And ComputerSum < 21 Then
If responseYouLost = MsgBoxResult.Yes Then
btnPlayAgain.PerformClick()
Else
btnQuit.PerformClick()
End If
ElseIf ComputerSum = 21 And PlayerSum <> 21 Then
If responseYouLost = MsgBoxResult.Yes Then
btnPlayAgain.PerformClick()
Else
btnQuit.PerformClick()
End If
ElseIf ComputerSum = PlayerSum Then
If responseYouDrew = MsgBoxResult.Yes Then
btnPlayAgain.PerformClick()
Else
btnQuit.PerformClick()
End If
ElseIf PlayerSum > 21 And ComputerSum > 21 Then
If responseYouDrew = MsgBoxResult.Yes Then
btnPlayAgain.PerformClick()
Else
btnQuit.PerformClick()
End If
End Sub
答案 0 :(得分:0)
删除第11行中的结束 但它在子
的末尾答案 1 :(得分:-1)
您可以更轻松地使用方式:
If PlayerSum > 21 Then PlayerSum = 0
If ComputerSum > 21 Then ComputerSum = 0
Dim response As MsgBoxResult
If PlayerSum > ComputerSum Then
response = MsgBox(youWonMsg, style, youWonTitle)
ElseIf ComputerSum > PlayerSum Then
response = MsgBox(youLostMsg, style, youLostTitle)
Else
response = MsgBox(youDrewMsg, style, youDrewTitle)
End If
If response = MsgBoxResult.Yes Then
btnPlayAgain.PerformClick()
Else
btnQuit.PerformClick()
End If
但是对于原始代码......请查看第11行的额外End If
结束语句。