Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27241

Newbe. Random word guessing game.

$
0
0
Having a heck of a time getting this to function the way I want. Should be just a basic generate number, guess what it is, count number of guesses, and let the user know whether to guess higher or lower kind of thing. Any suggestions? Very Very new to this as well.

Public Class Form1
Dim intnumb As Integer
Dim count As Integer


Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNumber.TextChanged


End Sub

Private Sub btnGuess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGuess.Click

End Sub



Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

End Sub

Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
count = 0
btnStart.Enabled = False
GroupBox1.Enabled = False
txtNumber.Enabled = True
btnGuess.Enabled = True
lblGuesses.Text = Str(count)
txtNumber.Focus()
txtNumber.Clear()
RandomNumber()


End Sub
Private Sub WrongGuess()
count += 1
lblGuesses.Text = Str(count)
If txtNumber.Text < intnumb Then
MessageBox.Show("Guess Higher")
ElseIf txtNumber.Text > intnumb Then
MessageBox.Show("Guess Lower")
End If
txtNumber.Focus()
txtNumber.Clear()

End Sub
Private Sub RightGuess()
count += 1
lblGuesses.Text = Str(count)
GroupBox1.Enabled = True
btnStart.Enabled = True
txtNumber.Enabled = False
btnGuess.Enabled = False
txtNumber.Text = Str(count)
MessageBox.Show("Correct!")
End Sub
Private Sub RandomNumber()
Randomize()
If RadioButton1.Checked = True Then
intnumb = Rnd() * 9 + 1
ElseIf RadioButton2.Checked = True Then
intnumb = Rnd() * 99 + 1
Else
intnumb = Rnd() * 999 + 1
End If
End Sub

Private Sub lblGuesses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblGuesses.Click
If txtNumber.Text <> "" Then
Try
If Integer.Parse(txtNumber.Text) = intnumb Then
RightGuess()
Else
WrongGuess()
End If
Catch ex As Exception
txtNumber.Clear()
txtNumber.Focus()
End Try
End If



End Sub
End Class

Viewing all articles
Browse latest Browse all 27241

Trending Articles