首先先插入两个文本框和一个命令按钮,为了清楚看出,文本框能放30个数大小足够。
Private Sub Command1_Click()
Dim a(1 To 30) As Integer, i As Integer, j As Integer, t As Integer
Text1.Text = ""
Randomize
a(1) = Int(Rnd * 90) + 1
Text1.Text = Text1.Text & a(1) & " "
For i = 2 To 30
t = i
Randomize
a(i) = Int(Rnd * 90) + 1
For j = 1 To i - 1
If a(i) = a(j) Then
i = t - 1
Exit For '去掉重复的数
End If
Next j
If i = t Then Text1.Text = Text1.Text & a(i) & " " '在文本框1中显示排列前的随机数
Next i
For i = 1 To 29 '由大到小排列无重复的随机数
For j = i + 1 To 30
If a(i) < a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next
Next
For i = 1 To 30
Text2.Text = Text2.Text & " " & a(i) '在文本框2中显示排列后的随机数
Next i
End Sub
来自:求助得到的回答