Private Sub Command1_Click()
Text1.Text = ""
Dim i As Integer
For i = 1 To 10
Randomize
Text1.Text = Text1.Text & IIf(Text1.Text = "", "", ",") & Int(Rnd(i) * 89) + 10
Next i
End Sub
Private Sub Command2_Click()
Text2.Text = ""
Dim tmpGrp() As String
tmpGrp = Split(Text1.Text, ",")
ResetOrder tmpGrp, 1
Dim i As Integer
For i = 1 To UBound(tmpGrp)
Text2.Text = Text2.Text & IIf(Text2.Text = "", "", ",") & tmpGrp(i)
Next i
End Sub
Function ResetOrder(ByRef tmpGrp() As String, ByVal sIndex As Integer) As String
'对所有数字排序
Dim i, j As Integer
Dim tmpN As Integer
For i = UBound(tmpGrp) To sIndex Step -1
If Val(tmpGrp(i)) > Val(tmpGrp(i - 1)) Then
'前一个比后一个小,则互换
tmpN = tmpGrp(i)
tmpGrp(i) = tmpGrp(i - 1)
tmpGrp(i - 1) = tmpN
End If
Next i
If sIndex < UBound(tmpGrp) Then
ResetOrder tmpGrp, sIndex + 1
End If
End Function
温馨提示:答案为网友推荐,仅供参考