Wow. Had another assignment, and it's all done.
Pretty easy stuff. I thinbk this code is alot easier on the eyes, and I really like the lay out.
Public Class Form1
Public guess As Integer
Public range As Integer
Public winner As String
Public winner_guess As Integer
Public winner_range As Double
Public players As Integer
Public beans As Integer
Public random_bean As New Random
Public bean_min As Integer = 50
Public bean_max As Integer = 500
Public already_show As Integer
Public play As Integer
Private Sub btnWinner_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWinner.Click
If already_show = 0 Then
If players > 0 Then
'Show Who Won: With Their Name and Guess, and Show the Actual Amount
lblWinner.Text = winner & " Wins with a Guess of " & winner_guess & "!"
lblBeans.Text = "There Are Actually " & beans & " Jelly Beans in the Jar."
txtName.Text = "press 'Play Again' to restart"
already_show = 1
Else
'If No Players Are Participating, then Tell the User
MessageBox.Show("Please Enter at Least One Guess!!!")
End If
Else
'Tell the User to Hit the Play Again Button to Restart
MessageBox.Show("Please Press the 'Play Again' Button to Restart.")
End If
End Sub
Public Sub calculate()
'Error Check for Guess Entry
If IsNumeric(txtGuess.Text) = False Then
MessageBox.Show("Please Enter a Valid Number.")
txtGuess.Focus()
Exit Sub
End If
'Read Guess from Text Box
guess = txtGuess.Text
'If Guess is too Low or too High, Get Another
If (guess < bean_min Or guess > bean_max) Then
MessageBox.Show("Please Enter a Value Between 51 and 499.")
play = 1
End If
If play = 0 Then
'Calculate Range of Guess
range = Math.Abs(beans - guess)
'If the Range is Lower than the Current Winning Range then Change Winner
If range < winner_range Then
winner = txtName.Text
winner_guess = guess
winner_range = range
End If
'Add the New Player
players = players + 1
lblPlayers.Text = players
'Ask to Add a New Player?
txtName.Text = "next please!"
txtGuess.Text = 0
End If
End Sub
Private Sub btnGuess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGuess.Click
play = 0
'*already_show* is Used to See if the User Has Pressed the *Show Winner* Button
'If They Have, then Don't Calculate Winner, but Tell Them to Restart
If already_show = 0 Then
'Get Calculations to See Who is Winning
calculate()
Else
'Tell the User to Hit the Play Again Button to Restart
MessageBox.Show("Please Press the 'Play Again' Button to Restart.")
End If
End Sub
Private Sub btnFinished_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFinished.Click
End
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Default Winning Range. Set High so First Guess Gets Winning Spot
winner_range = 999999999999999999
'Number of Beans in the Jar
beans = random_bean.Next(bean_min, bean_max)
End Sub
Private Sub btnAgain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgain.Click
'Change Values Back to Default for New Game
players = 0
lblPlayers.Text = players
txtName.Text = "enter your name here"
txtGuess.Text = 0
winner_range = 999999999999999999
beans = random_bean.Next(bean_min, bean_max)
lblWinner.Text = ""
lblBeans.Text = ""
already_show = 0
End Sub
End Class
Enjoy. I've attatched the program.