The document contains code for a number guessing game that generates a random secret number between 1 and 50. It tracks the number of guesses a player makes and provides feedback if their guess is too low, too high, or correct. The code handles the guess submission button click to check the guess against the secret number and update the message, and also contains a restart button that restarts the application.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
85 views
Exercise 12
The document contains code for a number guessing game that generates a random secret number between 1 and 50. It tracks the number of guesses a player makes and provides feedback if their guess is too low, too high, or correct. The code handles the guess submission button click to check the guess against the secret number and update the message, and also contains a restart button that restarts the application.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1
Public Class Form1
Const MIN As Integer = 1
Const MAX As Integer = 50 Dim count As Integer Private Sub btnCheckGuess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheckGuess.Click Randomize() Static secretNumber As Integer = Int((MAX - MIN + 1) * Rnd() + MIN) Dim guess As Integer guess = Val(Me.txtPlayerGuess.Text) count += 1 If guess = secretNumber Then Me.lblMessage.Text = "You Guessed it!" MessageBox.Show("You guessed it in" + Str(count) + "tries", "You did it") ElseIf guess < secretNumber Then Me.lblMessage.Text = "Too low." ElseIf guess > secretNumber Then Me.lblMessage.Text = "Too high" End If End Sub Private Sub Restart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Restart.Click Application.Restart() End Sub End Class