0

Hi all, I'm new to VB and I am doing a lottery program.

I managed to produce 7 random numbers but I am stuck with the sorting. All I can think of is to use if statements to do comparsion, but that will be a long way to do it and is very stupid if I do that .

I understand that there are bubble sorting, but I am not sure how to implement it.

I have another one which is to store the 7 numbers into 7 labels. And it's similar as below (just that a1 replace with Labal1.Caption and etc)

I will appreciate if you can help. Thanks.

```
Dim a1, a2, a3, a4, a5, a6, a7 As Integer
Private Sub cmdClick_Click()
cmdClick.Caption = "Please wait.."
cmdClick.Enabled = False
Sleep 2000 ' wait for 2 seconds.
a1 = Random(1, 45)
a2 = Random(1, 45)
If (a2 = a1) Then
a2 = Random(1, 45)
End If
a3 = Random(1, 45)
If (a3 = a2) Or (a3 = a1) Then
a3 = Random(1, 45)
End If
a4 = Random(1, 45)
If (a4 = a2) Or (a4 = a1) Or (a4 = a3) Then
a4 = Random(1, 45)
End If
a5 = Random(1, 45)
If (a5 = a4) Or (a5 = a3) Or (a5 = a2) Or (a5 = a1) Then
a5 = Random(1, 45)
End If
a6 = Random(1, 45)
If (a6 = a5) Or (a6 = a4) Or (a6 = a3) Or (a6 = a2) Or (a6 = a1) Then
a6 = Random(1, 45)
End If
a7 = Random(1, 45)
If (a7 = a6) Or (a7 = a5) Or (a7 = a4) Or (a7 = a3) Or (a7 = a2) Or (a7 = a1) Then
a7 = Random(1, 45)
End If
Text1.Text = a1 & " " & a2 & " " & a3 & " " & a4 & " " _
& a5 & " " & a6 & " " & a7
```