This document contains the code for a number guessing game program. It defines variables to store the computer-generated random number and the player's guess count. It contains methods to generate a random number based on the selected radio button, check if the player's guess is correct or incorrect, and update the display with feedback. The program allows the player to enter a guess, checks if it matches the random number, and provides feedback on the number of guesses and whether the guess was too high or too low.
This document contains the code for a number guessing game program. It defines variables to store the computer-generated random number and the player's guess count. It contains methods to generate a random number based on the selected radio button, check if the player's guess is correct or incorrect, and update the display with feedback. The program allows the player to enter a guess, checks if it matches the random number, and provides feedback on the number of guesses and whether the guess was too high or too low.
This document contains the code for a number guessing game program. It defines variables to store the computer-generated random number and the player's guess count. It contains methods to generate a random number based on the selected radio button, check if the player's guess is correct or incorrect, and update the display with feedback. The program allows the player to enter a guess, checks if it matches the random number, and provides feedback on the number of guesses and whether the guess was too high or too low.
This document contains the code for a number guessing game program. It defines variables to store the computer-generated random number and the player's guess count. It contains methods to generate a random number based on the selected radio button, check if the player's guess is correct or incorrect, and update the display with feedback. The program allows the player to enter a guess, checks if it matches the random number, and provides feedback on the number of guesses and whether the guess was too high or too low.
Download as DOCX, PDF, TXT or read online from Scribd
Download as docx, pdf, or txt
You are on page 1of 2
Public Class Form1
Dim ComputerNumber As Integer
Dim Count As Integer Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Count = 0 GroupBox1.Enabled = False Button1.Enabled = False TextBox1.Enabled = True Button1.Enabled = True Label1.Text = "Number of Guesses:" Label2.Text = "" TextBox1.Focus() TextBox1.Clear() GetNumber() End Sub Private Sub GetNumber() Randomize() If RadioButton1.Checked = True Then ComputerNumber = Rnd() * 9 + 1 ElseIf RadioButton2.Checked = True Then ComputerNumber = Rnd() * 99 + 1 ElseIf RadioButton3.Checked = True Then ComputerNumber = Rnd() * 999 + 1 End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If TextBox1.Text <> "" Then Try If Integer.Parse(TextBox1.Text) = ComputerNumber Then CorrectGuess() Else NotCorrectGuess() End If Catch ex As Exception TextBox1.Clear() TextBox1.Focus() MsgBox(ex.Message) End Try End If End Sub Private Sub CorrectGuess() Count += 1 Label1.Text = "Number of Guesses:" + Str(Count) GroupBox1.Enabled = True Button2.Enabled = True TextBox1.Enabled = False MsgBox("You Guessed my Number In " + Str(Count) + " Guesses!") End Sub Private Sub NotCorrectGuess() Count += 1 Label1.Text = "Number of Guesses:" + Str(Count) If Integer.Parse(TextBox1.Text) < ComputerNumber Then Label2.Text = "Your Guess Was Too low"
Else Label2.Text = "Your Guess was to high" End If TextBox1.Clear() TextBox1.Focus() End Sub End Class