我假定数组只有三个元素(8个元素你可以增加些代码),比较死的办法,你看看是否可以:
Public Sub rnd_integer()
Randomize
Dim MyNumber(3) As Integer
MyNumber(0) = Int((49 * Rnd) + 1)
line100: MyNumber(1) = Int((49 * Rnd) + 1)
If MyNumber(1) = MyNumber(0) Then
MsgBox "goto100"
GoTo line100
End If
line200: MyNumber(2) = Int((49 * Rnd) + 1)
If MyNumber(2) = MyNumber(1) Or _
MyNumber(2) = MyNumber(0) Then
MsgBox "goto200"
GoTo line200
End If
line300: MyNumber(3) = Int((49 * Rnd) + 1)
If MyNumber(3) = MyNumber(2) Or _
MyNumber(3) = MyNumber(1) Or _
MyNumber(3) = MyNumber(0) Then
MsgBox "goto300"
GoTo line300
End If
'num.Value = MyNumber(0) & "," & MyNumber(1) & "," & MyNumber(2) & "," & MyNumber(3) & "," & MyNumber(4) & "," & MyNumber(5) & "," & MyNumber(6) & "," & MyNumber(7)
For i = 0 To 3
Debug.Print MyNumber(i)
Next
End Sub
另外:把数组产生的数据存入某个表中,也可以使用dao或者ado的方法,向下循环,发现重复值就重新产生或者编辑后写入表。
这个方法应该更好一些。
[此贴子已经被作者于2006-5-26 23:34:08编辑过]
|