I'm making a random number game. The user only gets three chances to guess. If the user guesses wrong all three times, a message box should appear asking if he/she wants to restart, if yes then reset the game and it's controls. I'm not sure if i'm suppose to use some sort of counter to do this.
Public Class Game
Dim ranNum As Integer 'Declaring variable ranNum as an integer. This is a world level variable.
'This code will clear text box.
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
txtbxEnterNum.Clear()
End Sub
'This code will show your guess number and the random number the computer generated in
'a messagebox.show giving you the option to restart or quit.
Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click
Dim intCounter As Integer = 3
Dim intEnterNum As Integer = 0 ' Declaring intEnterNum as an integer
intEnterNum = CInt(txtbxEnterNum.Text) 'Using the convertion type Cint
If (intEnterNum <> ranNum) Then
intEnterNum = (MessageBox.Show("Your guess number is: " & CStr(txtbxEnterNum.Text) & " and the correct guess is: " & CStr(ranNum)))
Else
If MessageBox.Show("Correct! Do you wish to restart?", "Please Confirm Action", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
txtbxEnterNum.Clear()
ElseIf Windows.Forms.DialogResult.No Then
Me.Close()
End If
End If
End Sub
'This code will close the the program.
Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
Me.Close()
End Sub
'This code will generate a random number between 1-10
Private Sub btnNewGame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewGame.Click
ranNum = CInt(Rnd() * 10)
End Sub
End C