Random Numbers Stay the same
Random Numbers Stay the same
Random Numbers Stay the same
Random Numbers Stay the same
Random Numbers Stay the same
Random Numbers Stay the same Random Numbers Stay the same Random Numbers Stay the same Random Numbers Stay the same Random Numbers Stay the same Random Numbers Stay the same Random Numbers Stay the same Random Numbers Stay the same
Random Numbers Stay the same Random Numbers Stay the same
Random Numbers Stay the same
Go Back  Xtreme Visual Basic Talk > > > Random Numbers Stay the same


Reply
 
Thread Tools Display Modes
  #1  
Old 12-09-2013, 12:30 PM
ASmooveCriminal ASmooveCriminal is offline
Newcomer
 
Join Date: Dec 2013
Posts: 2
Default Random Numbers Stay the same


I am trying to create a code game in which you guess 9 different numbers between 1 and 9. The way it works is you input your numbers in 9 different text boxes then it will say which numbers are high, low, or correct. The problem is whenever I click the enter button it rerandomizes the numbers. How do I make it so the numbers don't change when I click enter?
Reply With Quote
  #2  
Old 12-09-2013, 12:36 PM
PlausiblyDamp's Avatar
PlausiblyDampRandom Numbers Stay the same PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,055
Default

Could you post the code you are using? It is very difficult to give advice when there is nothing to look at.

At a guess I would say you aren't storing the original series of random numbers anywhere and are regenerating them every time enter is pressed.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 12-09-2013, 12:43 PM
ASmooveCriminal ASmooveCriminal is offline
Newcomer
 
Join Date: Dec 2013
Posts: 2
Default

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MessageBox.Show("This is my game") 'Change this
End Sub

Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
Dim Input1 As Integer = TextBox1.Text
Dim Input2 As Integer = TextBox2.Text
Dim Input3 As Integer = TextBox3.Text
Dim Input4 As Integer = TextBox4.Text
Dim Input5 As Integer = TextBox5.Text
Dim Input6 As Integer = TextBox6.Text
Dim Input7 As Integer = TextBox7.Text
Dim Input8 As Integer = TextBox8.Text
Dim Input9 As Integer = TextBox9.Text
Dim Answer1 As Integer = Int(9 * Rnd() + 1)
Dim Answer2 As Integer = Int(9 * Rnd() + 1)
Dim Answer3 As Integer = Int(9 * Rnd() + 1)
Dim Answer4 As Integer = Int(9 * Rnd() + 1)
Dim Answer5 As Integer = Int(9 * Rnd() + 1)
Dim Answer6 As Integer = Int(9 * Rnd() + 1)
Dim Answer7 As Integer = Int(9 * Rnd() + 1)
Dim Answer8 As Integer = Int(9 * Rnd() + 1)
Dim Answer9 As Integer = Int(9 * Rnd() + 1)

If Input1 = Answer1 Then
Me.lbl1.Text = "Correct"
ElseIf Input1 < Answer1 And Input1 >= 1 Then
Me.lbl1.Text = "Low"
ElseIf Input1 > Answer1 And Input1 <= 9 Then
Me.lbl1.Text = "High"
Else
MessageBox.Show("Invald Input")
End If

If Input2 = Answer2 Then
Me.lbl2.Text = "Correct"
ElseIf Input2 < Answer2 And Input2 >= 1 Then
Me.lbl2.Text = "Low"
ElseIf Input2 > Answer2 And Input2 <= 9 Then
Me.lbl2.Text = "High"
Else
MessageBox.Show("Invald Input")
End If

If Input3 = Answer3 Then
Me.lbl3.Text = "Correct"
ElseIf Input3 < Answer3 And Input3 >= 1 Then
Me.lbl3.Text = "Low"
ElseIf Input3 > Answer3 And Input3 <= 9 Then
Me.lbl3.Text = "High"
Else
MessageBox.Show("Invald Input")
End If

If Input4 = Answer4 Then '4
Me.lbl4.Text = "Correct"
ElseIf Input4 < Answer4 And Input4 >= 1 Then
Me.lbl4.Text = "Low"
ElseIf Input4 > Answer4 And Input4 <= 9 Then
Me.lbl4.Text = "High"
Else
MessageBox.Show("Invald Input")
End If

If Input5 = Answer5 Then '5
Me.lbl5.Text = "Correct"
ElseIf Input5 < Answer5 And Input5 >= 1 Then
Me.lbl5.Text = "Low"
ElseIf Input5 > Answer5 And Input5 <= 9 Then
Me.lbl5.Text = "High"
Else
MessageBox.Show("Invald Input")
End If

If Input6 = Answer6 Then '6
Me.lbl6.Text = "Correct"
ElseIf Input6 < Answer6 And Input6 >= 1 Then
Me.lbl6.Text = "Low"
ElseIf Input6 > Answer6 And Input6 <= 9 Then
Me.lbl6.Text = "High"
Else
MessageBox.Show("Invald Input")
End If

If Input7 = Answer7 Then '7
Me.lbl7.Text = "Correct"
ElseIf Input7 < Answer7 And Input7 >= 1 Then
Me.lbl7.Text = "Low"
ElseIf Input7 > Answer7 And Input7 <= 9 Then
Me.lbl7.Text = "High"
Else
MessageBox.Show("Invald Input")
End If

If Input8 = Answer8 Then '8
Me.lbl8.Text = "Correct"
ElseIf Input8 < Answer8 And Input8 >= 1 Then
Me.lbl8.Text = "Low"
ElseIf Input8 > Answer8 And Input8 <= 9 Then
Me.lbl8.Text = "High"
Else
MessageBox.Show("Invald Input")
End If

If Input9 = Answer9 Then '9
Me.lbl9.Text = "Correct"
ElseIf Input9 < Answer9 And Input9 >= 1 Then
Me.lbl9.Text = "Low"
ElseIf Input9 > Answer9 And Input9 <= 9 Then
Me.lbl9.Text = "High"
Else
MessageBox.Show("Invald Input")
End If
End Sub
End Class
Reply With Quote
  #4  
Old 12-09-2013, 01:34 PM
Icehawke Icehawke is offline
Newcomer
 
Join Date: Aug 2013
Location: Elgin IL
Posts: 17
Default

Every time you click the button, you redeclare your variables with new random values. Try moving that section to form load and declare the variables global to the form.
Reply With Quote
  #5  
Old 12-09-2013, 01:48 PM
PlausiblyDamp's Avatar
PlausiblyDampRandom Numbers Stay the same PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,055
Default

I would also advise reading up on arrays and collections as it could reduce a lot of the cut and paste duplication in your code.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
Reply

Tags
code, game, random


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Random Numbers Stay the same
Random Numbers Stay the same
Random Numbers Stay the same Random Numbers Stay the same
Random Numbers Stay the same
Random Numbers Stay the same
Random Numbers Stay the same Random Numbers Stay the same Random Numbers Stay the same Random Numbers Stay the same Random Numbers Stay the same Random Numbers Stay the same Random Numbers Stay the same
Random Numbers Stay the same
Random Numbers Stay the same
 
Random Numbers Stay the same
Random Numbers Stay the same
 
-->