Re: Random Numbers help

  • 14 years ago

    Hi BlueTech

    Use this code

    Private Sub Command1_Click()
    Dim Num, Num1 As IntegerSmiley Face [:)]
    Dim ChkNum(7)
    Dim Flag As Boolean
    Flag = False
    Randomize
    'First loop creates Create random numbers 0 - 9
    For Num = 0 To 7
        ChkNum(Num) = Int((7 - 1 + 1) * Rnd + 1)
        'Do not check the first number
        If Num <> 0 Then
            'Second loop makes sure current number was not already used
            For Num1 = 0 To Num - 1
                If lb1.Caption = ChkNum(Num1) Then 'if current number matches any numbers already used
                    lb1.Caption = 11         'Set Current label to a number out of range
                    Num = Num - 1                  'Subtract 1 from First loops counter so it can generate an unused number for current label
                    Flag = False                   'Current number has been used so set flag to false
                    Exit For                       'Exit loop
                Else
                    Flag = True                    'Current number has not been used so set flag to true
                End If
           Next
        Else
            Flag = True                            'First number generated set flag to true
        End If
        If Flag = True Then                        'Flag true = number has not been used
            lb1.Caption = ChkNum(Num) - 1    'Write new number to proper label
            Flag = False
        End If
    Next
    End Sub































    regards

    DoctorMahdi

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If debugging is the process of removing software bugs, then programming must be the process of putting them in.” - Edsger Dijkstra