Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Game Programming (http://www.xtremevbtalk.com/-net-game-programming/)
-   -   Random Numbers Stay the same (http://www.xtremevbtalk.com/-net-game-programming/326653-random-stay.html)

ASmooveCriminal 12-09-2013 12:30 PM

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?

PlausiblyDamp 12-09-2013 12:36 PM

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.

ASmooveCriminal 12-09-2013 12:43 PM

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

Icehawke 12-09-2013 01:34 PM

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.

PlausiblyDamp 12-09-2013 01:48 PM

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.


All times are GMT -6. The time now is 08:12 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.