I've got an array containing dates in one list and cash values in t'other. I need it soting into acsending date order, relative to each dates' cash value.
Does anyone know how to do this?
Printable View
I've got an array containing dates in one list and cash values in t'other. I need it soting into acsending date order, relative to each dates' cash value.
Does anyone know how to do this?
First. Make sure the date is in the format yyyymmdd. So the year comes first followed by the month and then the day.
Once the date is in this fromat you can simply call a sorting algorithim to sort the dates for you.
As an example here is a quick sort algorithim. You pass it an array of data (in this eg Strings) and the lower bound (usually 0) and the upper bound (the number of elements in the list)
Iain.Code:' Sort the items in array values() with bounds min and max.
Sub Quicksort(values() As String, _
ByVal min As Long, _
ByVal max As Long)
Dim med_value As String
Dim hi As Long
Dim lo As Long
Dim i As Long
' If the list has only 1 item, it's sorted.
If min >= max Then Exit Sub
' Pick a dividing item randomly.
i = min + Int(Rnd(max - min + 1))
med_value = values(i)
' Swap the dividing item to the front of the list.
values(i) = values(min)
' Separate the list into sublists.
lo = min
hi = max
Do
' Look down from hi for a value < med_value.
Do While values(hi) >= med_value
hi = hi - 1
If hi <= lo Then Exit Do
Loop
If hi <= lo Then
' The list is separated.
values(lo) = med_value
Exit Do
End If
' Swap the lo and hi values.
values(lo) = values(hi)
' Look up from lo for a value >= med_value.
lo = lo + 1
Do While values(lo) < med_value
lo = lo + 1
If lo >= hi Then Exit Do
Loop
If lo >= hi Then
' The list is separated.
lo = hi
values(hi) = med_value
Exit Do
End If
' Swap the lo and hi values.
values(hi) = values(lo)
Loop ' Loop until the list is separated.
' Recursively sort the sublists.
Quicksort values, min, lo - 1
Quicksort values, lo + 1, max
End Sub
[Edited by Iain17 on 04-10-2000 at 04:37 PM]