我现在如下数组数据
M{A[1,2],B[3,1],C[1,3],D[3,6],E[3,2],F[1,8],G[3,3]}
我要得到的数据的排列是:
M{A[1,2],C[1,3]],F[1,8],B[3,1],E[3,2],G[3,3],D[3,6]}
也就是说,我不是对提大数组中的小数组的数据排序,而是对大数组中的小数组中的上标进
行排序,先对一维,一维相等就看二维了,谁以有好的方法,我给分.
M{A[1,2],B[3,1],C[1,3],D[3,6],E[3,2],F[1,8],G[3,3]}
我要得到的数据的排列是:
M{A[1,2],C[1,3]],F[1,8],B[3,1],E[3,2],G[3,3],D[3,6]}
也就是说,我不是对提大数组中的小数组的数据排序,而是对大数组中的小数组中的上标进
行排序,先对一维,一维相等就看二维了,谁以有好的方法,我给分.
好象VB没有这样的定义方法。楼主不妨把你的“大数组”、“小数组”的具体定义贴出来一下……
sort m //对字符串排序
For Each element In m
Debug.Print Right(element, 1)
Next
今天有时间给你写了个排序的子过程。'''''''''''''''''''''''''''''''''''''''
' 排序函数Sort
'colM参数,排序前的集合。
'colNew参数,排序后的集合
'ws参数,集合中小数组的维数,默认是2
'''''''''''''''''''''''''''''''''''''''''
Private Sub Sort(colM As Collection, colNew As Collection, Optional ws As Integer = 2)
Dim i As Integer
Dim j As Integer
Dim sx() As String
Dim tempStr As String
ReDim sx(colM.Count) As String
'把集合中的数组下标,转化成字串。方便排序。
For i = 1 To colM.Count
For j = 1 To ws
tempStr = "000" & Trim(Str(UBound(colM(i), j)))
sx(i) = sx(i) & Right(tempStr, 4)
Next
Next
'快速排序法
Dim TT As String
Dim ttg As Long
Dim gz() As Long
ReDim gz(colM.Count) As Long
For i = 1 To colM.Count
gz(i) = i
NextFor i = 1 To colM.Count
For j = i To colM.Count
If CLng(sx(i)) > CLng(sx(j)) Then
TT = sx(i)
ttg = gz(i)
sx(i) = sx(j)
sx(j) = TT
gz(i) = gz(j)
gz(j) = ttg
End If
Next
Next'把排序后数组添加到新集合。
For i = 1 To colM.Count
colNew.Add colM(gz(i))
NextEnd Sub
'点击窗口就能看到运行效果.我用的是繁体版的vb6,所以注释有乱码.Dim a(1, 3) As Long
Dim b(2, 3) As Long
Dim c(1, 2) As Long
Dim d(2, 7) As Long
Dim e(3, 3) As Long
Dim f(2, 4) As Long
'''''''''''''''''''''''''''''''''''''''
' 排序函数Sort
'colM参数,排序前的集合。
'colNew参数,排序后的集合
'ws参数,集合中小数组的维数,默认是2
''''''''''''''''''''''''''''''''''''''''' Private Sub Sort(colM As Collection, colNew As Collection, Optional ws As Integer = 2)
Dim i As Integer
Dim j As Integer
Dim sx() As String
Dim tempStr As String
ReDim sx(colM.Count) As String
'癸计舱夹,秈︽才﹃矪瞶,獽籔逼.
For i = 1 To colM.Count
For j = 1 To ws
tempStr = "000" & Trim(Str(UBound(colM(i), j)))
sx(i) = sx(i) & Right(tempStr, 4)
Next
Next
'ノе硉逼猭.
Dim TT As String
Dim ttg As Long
Dim gz() As Long
ReDim gz(colM.Count) As Long
For i = 1 To colM.Count
gz(i) = i
NextFor i = 1 To colM.Count
For j = i To colM.Count
If CLng(sx(i)) > CLng(sx(j)) Then
TT = sx(i)
ttg = gz(i)
sx(i) = sx(j)
sx(j) = TT
gz(i) = gz(j)
gz(j) = ttg
End If
Next
Next'竒筁逼计舱colNew栋.
For i = 1 To colM.Count
colNew.Add colM(gz(i))
NextEnd SubPrivate Sub Form_Click()
Dim col1 As New Collection
Dim col2 As New Collection
col1.Add (a)
col1.Add (b)
col1.Add (c)
col1.Add (d)
col1.Add (e)
col1.Add (f)
Dim i As IntegerPrint "排序前的下标"
For i = 1 To col1.Count
Print UBound(col1(i), 1) & "---" & UBound(col1(i), 2)NextSort col1, col2Print
Print "排序后的下标"
For i = 1 To col1.Count
Print UBound(col2(i), 1) & "---" & UBound(col2(i), 2)NextEnd Sub