Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: ADO Array Sort Recordset Object ASCENDING DESCENDING Multiple Column
;**************************************************************** ; ADO Array sort using a recordset object. ; ; ArraySort(Array,KeyColumn) ; ; Array = The array to be sorted ; It can be a 1 or two dimensional array. ; ; Order = @ASCENDING or @DESCENDING ; ; StartRow = The first row to be included in the sort. ; (Rows before that will be returned to the ; array in their original order.) ; ; Key1, Key2, Key3 = The columns to be sorted. ; ; The return value is a new array containing the sorted values. ; (The original array is not changed.) ; ; Developer: Alan Kreutzer ; ;**************************************************************************** #DefineFunction ArraySort(Array,Order,StartRow,Key1,Key2,Key3) TopRow = ArrInfo(Array,1)-1 TopCol = ArrInfo(Array,2)-1 ATitle = Arrayize("X.A.B.C","."); Names for the columns AValue = ArrDimension(4) ; Values for the columns RS=ObjectCreate("ADODB.RecordSet") ; Create recordset RS.fields.append("X",3) ; 3 = Integer Type RS.fields.append("A",200,256) ; 200 = String Type (202 = unicode) RS.Fields.append("B",200,256) RS.Fields.append("C",200,256) RS.Open For xRow = StartRow To TopRow AValue[0] = xRow AValue[1] = Array[xRow,Key1] AValue[2] = Array[xRow,Key2] AValue[3] = Array[xRow,Key3] RS.addNew(ATitle,AValue) Next Drop(ATitle,AValue) NewArr = ArrDimension(TopRow+1,TopCol+1) If Order == @DESCENDING RS.Sort="A DESC,B DESC,C DESC" Else RS.sort="A,B,C" EndIf RS.moveFirst xRow = 0 While xRow < StartRow For xCol=0 To TopCol NewArr[xRow,xCol] = Array[xRow,xCol] Next xRow = xRow + 1 EndWhile For xRow = StartRow To TopRow xSort = Int(RS.Fields("X").value) For xCol=0 To TopCol NewArr[xRow,xCol] = Array[xSort,xCol] Next RS.moveNext Next RS.close RS=0 Return NewArr #EndFunction
Article ID: W17676
Filename: ADO Array Sort.txt
File Created: 2009:07:13:09:55:06
Last Updated: 2009:07:13:09:55:06