Build Error? ?

thankins

Newcomer
Joined
Sep 24, 2003
Messages
24
Well I figured out how to do my program but I recieve this error in this part of my code
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

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!
 
Lotto is an array, and so is UserNum. You have to specify an element for UserNum. For example:
Visual Basic:
If Lotto(count) = UserNum(count) Then
 
When I add the count like you told me me too I recieve this error during run time
Code:
 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
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
 
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,
 
Back
Top