1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Private Sub Command1_Click()
Label1(0).Caption = Int(Rnd * 49 + 1)
For i = 1 To 6
'產生數字
Label1(i).Caption = Int(Rnd * 49 + 1)
For j = 0 To i - 1
'如果與已出現數字相同則重新產生數字
While Label1(i).Caption = Label1(j).Caption
Label1(i).Caption = Int(Rnd * 49 + 1)
Wend
Next j
Next i
End Sub

Private Sub Command2_Click()
'複製數字到排序陣列
For i = 0 To 5
Label3(i).Caption = Label1(i).Caption
Next i
'排序(雙層迴路)
For i = 0 To 4
For j = i + 1 To 5
'比較大小時要用數值比較
If Val(Label3(i).Caption) > Val(Label3(j).Caption) Then
t = Val(Label3(i).Caption)
Label3(i).Caption = Label3(j).Caption
Label3(j).Caption = t
End If
Next j
Next i
End Sub

Private Sub Command3_Click()
'複製數字到排序陣列
For i = 0 To 5
Label4(i).Caption = Label1(i).Caption
Next i
'排序(雙層迴路)
For i = 0 To 4
For j = i + 1 To 5
'比較大小時要用數值比較
If Val(Label4(i).Caption) < Val(Label4(j).Caption) Then
t = Val(Label4(i).Caption)
Label4(i).Caption = Label4(j).Caption
Label4(j).Caption = t
End If
Next j
Next i
End Sub