文本框有若干行数据,怎样随机重新排列?
127,14,18,25,312,35,412,42,44,47
123,128,129,11,15,212,21,23,27,36
122,123,21,23,39,15,18,19,33,37,
122,123,14,15,16,17,26,38,39,42,
129,11,13,19,27,312,34,35,38,45,
125,127,129,212,37,38,41,48,
25,13,27,22,23,112,12,16,15,45
123,127,11,16,212,28,37,43,47,48,
122,127,128,22,27,28,32,42,47,48,
122,112,19,212,23,312,31,34,38,48,
29,21,33,25,27,212,23,122,121,49
129,14,17,21,26,29,33,38,41,45
121,127,18,19,126,129,24,47,17,29,
127,22,41,13,25,29,32,16,17,18
把每行的顺序随机重新排列。
[解决办法]
Private Sub Command1_Click()
Dim s() As String, t() As String, i As Long, j As Long, k As Long, n As Long, temp As String
s = Split(Text1.Text, vbCrLf)
For i = 0 To UBound(s)
s(i) = Trim(s(i))
If s(i) Like "*, " Then s(i) = Left(s(i), Len(s(i)) - 1)
t = Split(s(i), ", ")
Randomize
For j = UBound(t) To 0 Step -1
n = Int(j * Rnd)
temp = t(j)
t(j) = t(n)
t(n) = temp
Next
s(i) = Join(t, ", ")
Next
Text1.Text = Join(s, vbCrLf)
End Sub