This is a guessing game and on the fifth attempt you are supposed to get a Game Over message box. My code gives a Game Over box but also gives a message box saying you have 0 attempts left. I need to eliminate the 0 attempts msgbox. Also if i guess correctly on the fifth try i get the msgbox you guessed correctly but i also get the game over box after. One last thing on my vbquestion box asking whether or not you want to play again i have to click the yes or no buttons twice. Thanks for your input.
Private Sub cmdGuess_Click()
GuessNum = txtGuessNum.Text
Output = lblOutput.Caption
xChances = xChances + 1
xAttempts = xAttempts + 1
If GuessNum = EnterNum Then
MsgBox "You guessed correctly and you did it on your " & xAttempts & _
" attempt!"
MsgBox "Play again?", vbQuestion + vbYesNo
If MsgBox("Play again?", vbQuestion + vbYesNo) = vbYes Then
Unload Me
frmEnterNum.Show
Else
Unload Me
End If
Else
MsgBox "That is incorrect you only have " & CInt(6 - xChances) & _
" more chances!"
End If
If xChances = 6 Then
MsgBox "Game Over"
MsgBox "Play again?", vbQuestion + vbYesNo
If MsgBox("Play again?", vbQuestion + vbYesNo) = vbYes Then
Unload Me
frmEnterNum.Show
Else
Unload Me
End If
End If
End Sub
Private Sub Form_Load()
xChances = 1
xAttempts = 0
End Sub
Private Sub cmdGuess_Click()
GuessNum = txtGuessNum.Text
Output = lblOutput.Caption
xChances = xChances + 1
xAttempts = xAttempts + 1
If GuessNum = EnterNum Then
MsgBox "You guessed correctly and you did it on your " & xAttempts & _
" attempt!"
MsgBox "Play again?", vbQuestion + vbYesNo
If MsgBox("Play again?", vbQuestion + vbYesNo) = vbYes Then
Unload Me
frmEnterNum.Show
Else
Unload Me
End If
Else
MsgBox "That is incorrect you only have " & CInt(6 - xChances) & _
" more chances!"
End If
If xChances = 6 Then
MsgBox "Game Over"
MsgBox "Play again?", vbQuestion + vbYesNo
If MsgBox("Play again?", vbQuestion + vbYesNo) = vbYes Then
Unload Me
frmEnterNum.Show
Else
Unload Me
End If
End If
End Sub
Private Sub Form_Load()
xChances = 1
xAttempts = 0
End Sub