Trouble with ending out an application

This application is a guessing game where the user has ten tries to guess a random number. After each guess the user is promted to guess higher or lower. When the user guesses the right answer a "Congratulations" message box appears.

The problem is when the user guesses correctly, the program should display the Congratulations message box and then end, however the loop keeps going. How can I make it stop

The code follows:

Private Sub TryButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TryButton.Click

Dim number As Integer

Dim num As Integer

Dim randomGenerator As New Random

Dim guess As Integer

number = randomGenerator.Next(0, 100)

guess = Integer.Parse(Me.guessBox.Text)

Do

If guess = number Then

MessageBox.Show("Congratulations!", "Guessing Game", MessageBoxButtons.RetryCancel, MessageBoxIcon.None, MessageBoxDefaultButton.Button1)

Else

If guess < number Then

guess = InputBox("Guess higher.", "Guessing Game")

Else

guess = InputBox("Guess lower.", "Guessing Game")

End If

End If

num = num + 1

Loop Until num = 10

MessageBox.Show("Game over you LOSE! The number was " & number, "Guessing Game", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

End Sub




Answer this question

Trouble with ending out an application

  • Tep

    Hmm, looks familiar. Put "Exit Do" after the congratulation.


  • HMCSQL2005

    Thank you!!



  • Trouble with ending out an application