Click to See Complete Forum and Search --> : Sorting Months


Raptors Fan
May 9th, 2001, 01:17 PM
Hi people, I'm sure I'm not the only one that ever needed to sort months in the right order and hope some of you can help me out.

I have a string array holding the names of the months randomly and would like to manipulate the array so that it will hold the months in the right order.

Muchas Gracias! (Thanks!)

Go Raptors!

Z LoveLife
May 9th, 2001, 01:24 PM
How about a 2 dimension array with something like this
February | 2
January | 1
March | 3

and then sort on the second field just a thought

Dave Sharp
May 9th, 2001, 01:48 PM
Use the Format function Format(<table entry>,"mm") when you do your comparisons in the sort routine.

If Format(table(1),"mm") > Format(table(2),"mm") then


Dave

sotoasty
May 9th, 2001, 01:55 PM
Ok, so I know this isn't the best, BUT I don't have a lot of time to do this up right. Place 3 Text boxes on a form, and name them "Text" (Make sure the indexes are 0,1,2) Place a command button on the form. Paste the following code into the form and run. It should sort the three months you type in.


private Sub Command1_Click()
Dim I as Integer
Dim J as Integer
Dim TT(2) as string
Dim TT1 as string

for I = 0 to 2
TT(I) = text(I).text + " 1, 1999"
next I
for I = 0 to 1
for J = I + 1 to 2
If CDate(TT(I)) > CDate(TT(J)) then
TT1 = TT(I)
TT(I) = TT(J)
TT(J) = TT1
End If
next J
next I
for I = 0 to 2
text(I).text = Left(TT(I), InStr(1, TT(I), " ") - 1)
next I

End Sub






Hope this helps.

Raptors Fan
May 9th, 2001, 02:20 PM
Thanks Dave Sharp, Z LoveLife, and especially sotoasty for your suggestions!