thankins Posted November 9, 2003 Posted November 9, 2003 Well I figured out how to do my program but I recieve this error in this part of my code If Lotto(count) = UserNum Then ' check to see if number match Operator '=' is not defined for Integers or 1 dimmensonal arrays of Integers And I dont know what it means. Here is my code Dim Lotto(4) As Integer Dim UserNum(4) As Integer Dim count As Integer Dim NumMatch As Integer Sub GetNum() For count = 0 To 4 UserNum(count) = Val(InputBox("Please enter a number for lotto number ", "lotto Number" & _ (count + 1).ToString)) Next count End Sub Sub Random5Numbers() Randomize() 'Initializes the random-number generator. For count = 0 To 4 'Puts the 5 numbers into the Array Lotto(count) = Int(0 + Rnd() * (9 - 0)) Next count 'Show the five numbers on a textbox, just for testing... 'MessageBox.Show(Lotto(0) & ";" & Lotto(1) & ";" & Lotto(2) & ";" & Lotto(3) & ";" & Lotto(4)) End Sub Sub CheckNum() If Lotto(count) = UserNum Then ' check to see if number match NumMatch = NumMatch + 1 ' if they do, then add 1 to the count of numbers matched End If lblDisplay.Text = NumMatch End Sub Any help wouldbe great! Quote
*Experts* Volte Posted November 9, 2003 *Experts* Posted November 9, 2003 Lotto is an array, and so is UserNum. You have to specify an element for UserNum. For example:If Lotto(count) = UserNum(count) Then Quote
thankins Posted November 9, 2003 Author Posted November 9, 2003 When I add the count like you told me me too I recieve this error during run time If Lotto(count) = UserNum(count) An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Hankins11_08_03.exe Additional information: Index was outside the bounds of the array. Again here is my code Dim Lotto(4) As Integer Dim UserNum(4) As Integer Dim count As Integer Dim NumMatch As Integer Sub GetNum() For count = 0 To 4 UserNum(count) = Val(InputBox("Please enter a number for lotto number ", "lotto Number" & _ (count + 1).ToString)) CheckNum() '<== Do the nubmer check here. Next count End Sub Sub Random5Numbers() Randomize() 'Initializes the random-number generator. For count = 0 To 4 'Puts the 5 numbers into the Array Lotto(count) = Int(0 + Rnd() * (9 - 0)) Next count 'Show the five numbers on a textbox, just for testing... 'MessageBox.Show(Lotto(0) & ";" & Lotto(1) & ";" & Lotto(2) & ";" & Lotto(3) & ";" & Lotto(4)) End Sub Sub CheckNum() Dim frmSplash As New frmSplashScreen() 'declare instance of Form If Lotto(count) = UserNum(count) Then ' check to see if number match NumMatch = NumMatch + 1 ' if they do, then add 1 to the count of numbers matched lblDisplay.Text = NumMatch If NumMatch = 5 Then ' check to see if user got all right. frmSplash.Show() ' if they got them all right, then show the Form End If End If End Sub Quote
Mehyar Posted November 10, 2003 Posted November 10, 2003 Where do you cal Random5Numbers() ???? Moreover, you do not need the variable count to be a private just declare it in every method and use it. Or if you still insist on it being private remember to set it to 0 everytime you finishe from it. Hope this helps, Quote Dream as if you'll live forever, live as if you'll die today
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.