Private Sub Command1_Click() Dim strTest As String Dim arrTest() As String Dim intIndex As Integer Dim arrResult() As String Dim intTest As Integer Dim i As Integer, j As Integer Dim blnEquat As Boolean Dim blnFirst As Boolean
blnFirst = True Do While i <= 4 intIndex = Rnd() * UBound(arrTest) blnEquat = False If Not blnFirst Then For j = LBound(arrResult) To UBound(arrResult) If arrResult(j) = arrTest(intIndex) Then blnEquat = True Exit For End If Next j Else '第一次执行时,不需要比较,否则会出错 blnFirst = False End If
If Not blnEquat Then ReDim Preserve arrResult(i) arrResult(i) = arrTest(intIndex) i = i + 1 End If Loop
Dim strTest As String
Dim arrTest() As String
Dim intIndex As Integer
Dim arrResult() As String
Dim intTest As Integer
Dim i As Integer, j As Integer
Dim blnEquat As Boolean
Dim blnFirst As Boolean
strTest = "1,15,28,35,16,45,169,18,14,17,19,56,49"
arrTest = Split(strTest, ",")
blnFirst = True
Do While i <= 4
intIndex = Rnd() * UBound(arrTest)
blnEquat = False
If Not blnFirst Then
For j = LBound(arrResult) To UBound(arrResult)
If arrResult(j) = arrTest(intIndex) Then
blnEquat = True
Exit For
End If
Next j
Else
'第一次执行时,不需要比较,否则会出错
blnFirst = False
End If
If Not blnEquat Then
ReDim Preserve arrResult(i)
arrResult(i) = arrTest(intIndex)
i = i + 1
End If
Loop
MsgBox Join(arrResult, vbTab)
End Sub