Adblock breaks this site

Help

Discussion in 'Programming General' started by tomanderson12, Nov 12, 2008.

  1. tomanderson12

    tomanderson12 Member

    Joined:
    Jan 21, 2008
    Posts:
    53
    Referrals:
    0
    Sythe Gold:
    0
    Help

    I need some help, iv been working on this lottery 'game' if you will, I had a problem a while back with numbers generating but making sure they dont generate the same, that was fixed now im trying to compare the users numbers to the generated if they are correct then a label changes to how ever many matched i have this code

    Code:
    Private Sub Text2_Change(Index As Integer)
    
    
    End Sub
    Private Sub cmdRun_Click()
    
       'Dimension the variables used in the programme
        Dim intNumber As Integer
        Dim arrNumber(0 To 5) As Integer
        Dim intCount As Integer
        Dim intCheck As Integer
        Dim count3 As Integer
        Dim temp As Integer
        Dim count As Integer
        
    '*******************************************************************
            'Sets Count
            For intCount = 0 To (txtMachine.count - 1)
            
                Randomize
                intNumber = Int(Rnd * 49) + 1 ' Random number 1 to 49
                arrNumber(intCount) = intNumber
                
                If intCount > 0 Then
                
    ReCheck:
                
                    For intCheck = 0 To intCount - 1
                    
                        If intNumber = arrNumber(intCheck) Then
                        
                            intNumber = Int(Rnd * 49) + 1
                            arrNumber(intCount) = intNumber
                          temp = 0
    
                            
    GoTo ReCheck
                            
                        End If
                        
                    Next intCheck
                    
                End If
                
                txtMachine(intCount).Text = intNumber
                    
                    
                    
            Next intCount
            
            
        If txtUser(Index) = txtMachine(Index).Text Then
            lblMatch.Caption = lblMatch.Caption + 1
            
            
        End If
    '*******************************************************************
            txtUser(0).Enabled = False
            txtUser(1).Enabled = False
            txtUser(2).Enabled = False
            txtUser(3).Enabled = False
            txtUser(4).Enabled = False
            txtUser(5).Enabled = False
            
    '*******************************************************************
    
    
    If Val(lblMatch.Caption) < 3 Then
        MsgBox ("You have won nothing")
        lblMatch.Caption = "0"
    End If
    If Val(lblMatch.Caption) = 3 Then
        MsgBox ("You have won £5")
        lblMatch.Caption = "0"
    End If
    If Val(lblMatch.Caption) = 4 Then
        MsgBox ("You have won £15")
        lblMatch.Caption = "0"
    End If
    If Val(lblMatch.Caption) = 5 Then
        MsgBox ("You have won £50")
        lblMatch.Caption = "0"
    End If
    If Val(lblMatch.Caption) = 6 Then
        MsgBox ("You have won £250")
        lblMatch.Caption = "0"
    End If
    
    
    
    End Sub
    
    Private Sub Form_Activate()
    
    'Sets the focus for the text boxes when form loads
    txtUser(Index).SetFocus
    
    End Sub
    
    Private Sub txtUser_Change(Index As Integer)
    
    'Makes sure that zeros are not entered
    
    'If txtUser(Index).Text < 1 Then
     '   MsgBox ("You need to choose a number greater than Zero")
    'End If
    
    
    'Makes sure that all the users numbers are entered
    If txtUser(Index).Text = "" Then
        MsgBox ("You must enter your chosen numbers to see if you have won")
        cmdRun.Enabled = False
    Else
        cmdRun.Enabled = True
    End If
    
    
    'checks to see if the number entered is between 1 and 49
    If Val(txtUser(Index).Text) > 49 Then
    
        MsgBox ("Please Enter a Number Between 1 and 49")
        
            txtUser(Index).BackColor = &H8080FF
            'Clears the text box ready for the next number
             txtUser(Index).Text = ""
    Else
        txtUser(Index).BackColor = &H80000005
        
    End If
    
    
    
    'If lblCheck.Caption = "6" Then
    '    Me.cmdRun.Enabled = True
    'End If
        
    End Sub
    
    Private Sub txtUser_LostFocus(Index As Integer)
    If Index > 0 Then
        If txtUser(Index) = txtUser(Index - 1) Then
            MsgBox ("Sorry but you have two of the same numbers")
            txtUser(Index).BackColor = &H8080FF
            
        End If
    End If
    End Sub
    That is all the code from there you should be able to figure out the names etc

    Help on how to get the caption to change will be useful
     
  2. Nullware

    Nullware Guru

    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0
    Help

    What exactly do you want help with? I'm sorry if I misunderstood but you just posted a couple short explanations (in somewhat broken english) with a large chunk of code in between and it's not very clear what the problem is.
     
  3. tomanderson12

    tomanderson12 Member

    Joined:
    Jan 21, 2008
    Posts:
    53
    Referrals:
    0
    Sythe Gold:
    0
    Help

    Sorry, i posted this kinda late for my time,

    Once the numbers have been generated, and the users numbers have been entered i want it to check how many match then display how many match on a label (lblMatch)
     
  4. Darthatron

    Darthatron Massive Troll
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    May 22, 2006
    Posts:
    1,612
    Referrals:
    3
    Sythe Gold:
    0
    Help

    What's wrong with using 2 For Loops?

    Code:
    Dim a as long, b as long, lCount as long
    
    For a = 0 To TotalCountOfNumbers
        For b = 0 To TotalCountOfNumbers
            If Label(a).Caption = Text(b).Text Then
                lCount = lCount + 1
            End If
        Next b
    Next a
    
    lblMatch.Caption = lCount
    TotalCountOfNumbers would be how many numbers there are to compare.
    Label() is the label array that has the numbers that were generated.
    Text() is the textbox array that holds the users inputs.
    lblMatch is the label that will hold the total number of matches.
    _______________

    If you need more help, post. >_>
     
  5. tomanderson12

    tomanderson12 Member

    Joined:
    Jan 21, 2008
    Posts:
    53
    Referrals:
    0
    Sythe Gold:
    0
    Help

    Thanks for the help, I got it to work
     
< Help with atan2f function! | RuneScape not loading in .NET IDE? >


 
 
Adblock breaks this site