Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Re-ordering an array

Status
Not open for further replies.

DaveMere

Programmer
Nov 24, 2003
20
GB
Hi all.

Is it possible to re-order the contents of a 2-dimensional array according to the contents of one field?

I have an array;
Code:
LOC(1 to 5, 1 to n)
which consists of n returned records with 5 fields each. I'd like to reorder this array several times in the same function, each time ordering by a different one of it's 5 data fields.

Does anyone know of a command/method that will do this, or will I have to design a function myself?

Thanks,

DaveMere
 
' Try creating a custom ADO recordset like this

Dim r as new ADODB.Recordset

r.Fields.Append "Field1", adVarChar, 255
r.Fields.Append "Field2", adVarChar, 255
r.Fields.Append "Field3", adVarChar, 255
r.Fields.Append "Field4", adVarChar, 255
r.Fields.Append "Field5", adVarChar, 255
r.CursorType = adOpenStatic
r.LockType = adLockOptimistic
r.Open
r.AddNew

' load the values here...then call Update like below

r.update

' Once uv loaded ur data use the sort property of ADO

r.Sort = "Field1" ' Defaults to ascending
r.Sort = "Field1 ASC" ' Ascending sort
r.Sort = "Field1 DESC" ' Descending sort

' Sort on two fields, LastName in ascending order, and
' FirstName in descending order.

r.Sort = "Field1 ASC, Field2 DESC"

Hope this helps

dr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top