程式碼如下
Private Sub Command2_Click()
Dim Arr(8) As Integer
Dim i As Integer
Dim j As Integer
Dim YN As Boolean
Dim rndCompare As Integer
Do
'取 1-9 的亂數
Randomize (Second(Now))
rndCompare = Int(Rnd * (UBound(Arr) + 2))
YN = False
'找到重覆亂數
For i = 0 To UBound(Arr)
If rndCompare = Arr(i) Then YN = True: Exit For
Next
'不重覆亂數放置到陣列
If YN = False Then
Arr(j) = rndCompare
Command1(j).Caption = Arr(j)
j = j + 1
If j > UBound(Arr) Then Exit Do
End If
Loop
End Sub
沒有留言:
張貼留言