在窗体内加入控件text1,text2,text3,command1,然后复制下面代码,运行即可。当你在text1内输入数字后,在text2内输入数字范围,按command1按钮,text3就会显示N个不重复随机数。
Option Explicit
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer, ss, tt() As Integer, outzf As String
ss = Split(Text1.Text, ",")
ReDim tt(UBound(ss))
k = Val(Text2.Text)
If k > UBound(ss) + 1 Then
MsgBox "你输入要产生的数量大于数字列表,请更正!"
Exit Sub
End If
'Randomize
Do
j = Rnd * k
If tt(j) = 0 Then
tt(j) = 1
outzf = outzf & ss(j) & ","
i = i + 1
End If
DoEvents
Loop Until i = k
Text3.Text = outzf
End Sub
温馨提示:答案为网友推荐,仅供参考