数组a用于存储产生的10个随机整数,函数f(x)用于判断随机整数x与已生成的整数是否有重复,若有重复则返回True,否则返回False。
Dim a(1 To 10) As Integer
Function f(x As Integer) As Boolean
′代码略
End Function
Private Sub Commandl_Click()
Dim n As Integer ′n用于统计已经产生的随机整数个数
Dim i As Integer.j As Integer
Dim x As Integer.k As Integer
Randomize ′初始化Rnd函数
n=0
List1.Clear ′清除列表框中内容
List2.Clear
Do While n<10
x=① ′产生[1,999]范围内的随机整数
If Not f(x) Then
n=n+1
a(n)=x
List1.AddItem Str(a(n))
End If
Loop
For i=1 To 9
For j=10 To i+1 step -1
If ② Then
k=a(j):a(j)=a(j-1):a(j-1)=k
End If
Next j
Next i
For i=1 To 10
List2.AddItem Str(a(i))
Next i
End Sub