I was given a task of creating a lucky draw program.

1.Total numbers of accounts are 00001 to 99999.
2.But only 131 accounts will be chosen.
3.3 sections - 1 account for 1 car, 20 accounts for 20 iPhone, 10 accounts for 10 Samsung 4.Galaxy & 100 accounts for $100 Voucher.
5.Use randomize.
6.Use sorting - ascending order.

I did manage to create the program, but I don't know how to sort the numbers according to their section.

Did I do incorrectly? Or do I need to add/edit something?

Private Sub Command1_Click()

Dim arrayno(1 To 131)
Dim luckyno
Dim counter
Dim check

For counter = 1 To 131
    luckyno = Int((99999 * Rnd) + 1)
    For check = 1 To 131
        If luckyno = arrayno(check) Then
            GoTo start
        End If
    Next check
    arrayno(counter) = luckyno
    Text1(counter - 1) = arrayno(counter)
Next counter
End Sub

Private Sub Command2_Click()

Unload Me

End Sub

Private Sub Form_Load()

Dim i As Integer
For i = 1 To 130
Text1(i).Text = ""
Next i

End Sub

Edited by Minami: change title

Attachments Untitled.jpg 65.75 KB
6 Years
Discussion Span
Last Post by WaltP

Major problems:
1) Randomize should be used when the program starts, not when you click your button.
2) Never use GOTO, it's unnecessary and in your case does nothing worthwhile.
3) In line 13, how can luckyno = arrayno(check) since arrayno(check) has no value?
4) And through whatever magic might make luckyno = arrayno(check) true, why would you want to start all over?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.