Private Sub GameForm_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
'verify that the user wants to exit the application
Dim button As Integer
button = MessageBox.Show("Do you want to exit?", "Guessing Game", MessageBoxButtons.YesNo, _
MessageBoxIcon.Exclamation)
'if the user selects the No button, don't close the form
If button = DialogResult.No Then
e.Cancel = True
End If
End Sub
Private Sub uiExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uiExitButton.Click
Me.Close()
End Sub
Private Sub uiCheckButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uiCheckButton.Click
Dim guessNum As Integer
Dim randomNum As Integer
'display variables
guessNum = Integer.Parse(Me.uiGuessTextBox.Text)
randomNum = Integer.Parse(Me.uiGeneratedNumLabel.Text)
attemptNum = attemptNum + 1
'display attemptNum label control
If attemptNum < 10 And randomNum <> guessNum Then
If attemptNum = 9 Then
Me.uiAttemptTextLabel.Text = "You have 1 attempt left"
Else
Me.uiAttemptTextLabel.Text = "You have " & (10 - (attemptNum)) & " attempts left"
End If
ElseIf attemptNum = 10 AndAlso randomNum <> guessNum Then
Me.uiAttemptTextLabel.Text = "You lose!"
ElseIf attemptNum <= 10 AndAlso randomNum = attemptNum Then
Me.uiAttemptTextLabel.Text = "You Win!"
End If
'determine if guess is greater than, less, than, or equal to the generated random number
If attemptNum < 10 AndAlso guessNum <> randomNum Then
Dim button As Integer
Do
If guessNum < randomNum Then
button = MessageBox.Show("Please choose a higher number", "Too Low", _
MessageBoxButtons.OK, MessageBoxIcon.Hand)
Else
button = MessageBox.Show("Please choose a lower number", "Too High", _
MessageBoxButtons.OK, MessageBoxIcon.Hand)
End If
Me.uiGuessTextBox.Focus()
Me.uiGuessTextBox.SelectAll()
Loop Until button = DialogResult.OK
ElseIf guessNum = randomNum Then
Dim button As Integer
MessageBox.Show("Congratulations! You guessed the right answer! Would you like to play again?", _
"Correct!", MessageBoxButtons.YesNo, MessageBoxIcon.Hand)
If Button = DialogResult.No Then
Me.Close()
Else
This is where I need help!
End If
ElseIf attemptNum > 10 AndAlso guessNum <> randomNum Then
Dim button As Integer
MessageBox.Show("Sorry but the correct answer is " & Convert.ToString(randomNum) & "! Please try again", _
"Try Again", MessageBoxButtons.YesNo, MessageBoxIcon.Hand)
If Button = DialogResult.No Then
Me.Close()
Else
This is where I need help!
End If
End If
End Sub
Private Sub GenerateRandomNumbers()
'generates a random number
Dim randomNum As Integer
Dim randomGenerator As New Random
'Generate the random number
randomNum = randomGenerator.Next(0, 101)
'display random numbers----------------------------Make sure to remove this code, along with the box uiGeneratedNumLabel
Me.uiGeneratedNumLabel.Text = Convert.ToString(randomNum)
Me.uiAttemptTextLabel.Text = "You have 10 attempts left"
End Sub
Private Sub GameForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
'generate the random number and populate the number of attempts on load
Call GenerateRandomNumbers()
End Sub