Public Declare Function CallFuncPtr Lib "user32" Alias "CallWindowProcA" (ByVal ptrFunc As Long, _
ByVal ptrElem1 As Long, ByVal ptrElem2 As Long, ByVal ptrElem3 As Long, ByVal ptrElem4 As Long) As Boolean
Type SortParams
Data() As Variant '二维数组
Index() As Long '索引数组
End Type
Public Sub mcSort(ByVal FuncPtr As Long, ByRef Params As SortParams)
Dim nRow As Long
Dim nRow2 As Long
Dim nCol As Long
Dim tmpSwap As Variant
Dim unused As Long
Dim i As Long, j As Long
'建立索引
ReDim Params.Index(UBound(Params.Data) - LBound(Params.Data) + 1)
For i = LBound(Params.Data) To UBound(Params.Data)
Params.Index(j) = i
j = j + 1
Next i
'冒泡排序
For nRow = LBound(Params.Index) To UBound(Params.Index) - 1
For nRow2 = UBound(Params.Index) To nRow + 1 Step -1
If CallFuncPtr(ByVal FuncPtr, ByVal VarPtr(Params), ByVal VarPtr(Params.Index(nRow2 - 1)), ByVal VarPtr(Params.Index(nRow2)), ByVal VarPtr(unused)) Then '调用用户自定义比较规则进行两条记录比较
tmpSwap = Params.Index(nRow2)
Params.Index(nRow2) = Params.Index(nRow2 - 1)
Params.Index(nRow2 - 1) = tmpSwap
End If
Next nRow2
Next nRow
End Sub
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) | Powered by Discuz! X3.3 |