If Timer1.Enabled = False Then
Timer1.Enabled = True
Command1.Caption = "停止"
Else
Timer1.Enabled = False
Command1.Caption = "開始"
End If
End SubPrivate Sub Form_Load()
Command1.Caption = "開始"
Timer1.Enabled = False
Timer1.Interval = 100
End SubPrivate Sub Timer1_Timer()
Dim tmpNum(7) As Integer
Dim i As Integer, j As Integer
Text1 = ""
Randomize '初始化隨機數種子
For i = 0 To 6
ReGet:
tmpNum(i) = Int(Rnd() * 32) + 1
If i > 0 Then
For j = 1 To i
'數字重復則從新得到
If tmpNum(i) = tmpNum(j - 1) Then GoTo ReGet:
Next
End If
DoEvents
Next
'排序
For i = 0 To 6
For j = 0 To 5
If tmpNum(j) > tmpNum(j + 1) Then
tmpNum(7) = tmpNum(j)
tmpNum(j) = tmpNum(j + 1)
tmpNum(j + 1) = tmpNum(7)
End If
DoEvents
Next
DoEvents
Next
For i = 0 To 6
Text1 = Text1 & tmpNum(i) & ","
Next
Text1 = Left(Text1, Len(Text1) - 1)
End Sub