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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP Sort by Date

Status
Not open for further replies.

alexander1113

Programmer
Dec 26, 2004
26
US
To whomever can assist,

Im trying to sort a 2 dimensional array by date. Can anyone help. so my array looks like this
'

array(0,0) = "John"
array(1,0) = "New York"
array(2,0) = "New York"
array(3,0) = "5/7/2004"
array(0,1) = "Steve"
array(1,1) = "Maryland"
array(2,1) = "Baltimore"
array(3,1) = "5/4/2004"
etc...

There's more records but you get the picture. Thanks in advance.

 
Hello alexander1113,

One way to proceed is this.
[0] You naming array(0,0) etc is no good. Array is a reserved word. Let me refer it as A(0,0) etc.
[1] Make a dictionary object with keys (0,1,2,...,ubound(A,2)) and the corresponding items (A(3,0),A(3,1),...).
[2] Use this dictionary as to sort against items.
[2.1] In vbs, you have to device the sorting algorithm. A ready-made using shell sort on dictionary object is available in ms article, say:
[3] After objDict being sorted, you get the order of the keys rearranged in some order like (5,2,0,3,...). From this order, you rearrange you 2-d array A, say by making a mirror array B. Putting those entries A to B in that order according to the 2nd dim of A. After B is made, put B back to A in the natural order.
[4] Erase B by vbs erase function, just to play safe.

The way to conduct re-ordering [3] and [4] can be improved if memory resource is scarce. But, that is the easiest one.

regards - tsuji
 
Further note:

Another substantially different way is to feed the array elements to a disconnected record set. Then, sort the record set on the date entry field . Rebuild the array from the sorted record set.

- tsuji
 
i would go for creating your own class.
with properties like

.FirstName
.State
.Date
.etc

you could then hold these objects in an array or dictionary object as tsuji suggests
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top