In college I've been asked to make a VB program that generates a random number from 1 - 40, the user has to guess this number and if they are wrong it tells them to go higher or lower till they get it correct, then tell them how many attempts it took them to guess, I chose to use textboxes (program will look better that way) and have tried to make it look the part, looking at it I don't think I'm too far off (bare in mind I'm a beginner lol) I have a pic box covering the program at the start, clicking on this generates the number and make the pic disappear, then user interface is revealed, problem is tho when I type my number in the box then press the button to guess it seems to just freeze, I'm not even getting infinite loops or errors :S i'll post my code below, any bit of wisdom is welcome :)
Public Class Form1
Dim guess As Integer
Dim count As Integer = 0
Dim answer As Integer
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles picStart.Click
Randomize()
txtGuess.Clear()
answer = Int(Rnd() * 40 + 1)
picStart.Visible = false
End Sub
Private Sub btnGuess_Click(sender As Object, e As EventArgs) Handles btnGuess.Click
guess = txtGuess.Text
Do While Not (guess = answer)
count = count + 1
If guess < answer Then
lblHigher.Visible = True
End If
If guess > answer Then
lblLower.Visible = True
End If
txtGuess.Clear()
Loop
If guess = answer Then
picWin.Visible = True
lblAttempts.Visible = True
txtAttempts.Visible = True
txtAttempts.AppendText(count)
End If
End Sub
Private Sub PictureBox1_Click_1(sender As Object, e As EventArgs) Handles picWin.Click
picWin.Visible = False
picStart.Visible = True
lblAttempts.Visible = False
txtAttempts.Visible = False
End Sub
End Class
Public Class Form1
Dim guess As Integer
Dim count As Integer = 0
Dim answer As Integer
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles picStart.Click
Randomize()
txtGuess.Clear()
answer = Int(Rnd() * 40 + 1)
picStart.Visible = false
End Sub
Private Sub btnGuess_Click(sender As Object, e As EventArgs) Handles btnGuess.Click
guess = txtGuess.Text
Do While Not (guess = answer)
count = count + 1
If guess < answer Then
lblHigher.Visible = True
End If
If guess > answer Then
lblLower.Visible = True
End If
txtGuess.Clear()
Loop
If guess = answer Then
picWin.Visible = True
lblAttempts.Visible = True
txtAttempts.Visible = True
txtAttempts.AppendText(count)
End If
End Sub
Private Sub PictureBox1_Click_1(sender As Object, e As EventArgs) Handles picWin.Click
picWin.Visible = False
picStart.Visible = True
lblAttempts.Visible = False
txtAttempts.Visible = False
End Sub
End Class