Help with Random Numbers

Discussion in 'Programming General' started by tomanderson12, Oct 14, 2008.

Help with Random Numbers
  1. Unread #1 - Oct 14, 2008 at 5:51 PM
  2. tomanderson12
    Joined:
    Jan 21, 2008
    Posts:
    53
    Referrals:
    0
    Sythe Gold:
    0

    tomanderson12 Member

    Help with Random Numbers

    Hello guys, I have a problem I have a program that is the generate random numbers but not the same one again I thought I had it with this but all it does is display the same number again in the 6 text boxes i have which are all control arrays by the way

    So basically when you click cmdRun it generates random numbers into 6 text boxes called txtMachine which are control arrays, but it doesn't generate random numbers in each its the same one for all the boxes

    the code is

    Code:
    Private Sub cmdRun_Click()
    
      ' Dimension the variables used in the programme
        Dim intNumber As Integer
        Dim arrNumber(0 To 5) As Integer
        Dim count As Integer
        Dim i As Integer
        Dim x As Integer
        Dim y As Integer
        
        
        
            'Sets Count
            For x = 0 To 5
            
            
    
                Randomize
                
                intNumber = Int(Rnd * 49) + 1 ' Random number 1 to 49
                For y = 0 To 5
                    ' Check arrNumber (y)
                    'If intnumber has already been selected,
                    'Then go and select another one.
                If intNumber = arrNumber(y) Then
    
                    End If
                    
                Next y
    
                    arrNumber(x) = intNumber
                
                    txtMachine(count).Text = (arrNumber(i))
                    count = i + 1
                Next x
            
            '----------------------------------------------------
            
            For i = 0 To 5
                
            Next
            
    
    End Sub
     
  3. Unread #2 - Oct 15, 2008 at 3:56 AM
  4. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Help with Random Numbers

    This should work, if you need anything explained just post back.
    Code:
    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
        
            '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
                            GoTo ReCheck
                            
                        End If
                        
                    Next intCheck
                    
                End If
                
                txtmachine(intCount).Text = intNumber
                    
            Next intCount
    
    End Sub
     
  5. Unread #3 - Oct 15, 2008 at 5:06 PM
  6. tomanderson12
    Joined:
    Jan 21, 2008
    Posts:
    53
    Referrals:
    0
    Sythe Gold:
    0

    tomanderson12 Member

    Help with Random Numbers

    Thanks Covey, worked well
     
< how to bind two exe in one | [TUT][C] Using the IF statement >

Users viewing this thread
1 guest


 
 
Adblock breaks this site