Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default sort routine puts in wrong order

I am attempting to modify this sort routine(which I didn't create) to sort a
series of variable length string arrays using permit numbers correctly. The
numbers that appear sort like this: 01316, 01327, 01329, 02884, 02888,
02889, 13198, 13200, 13580, 1937, 1958, 2157, 2289, 2789, 2855, 5160, 5837,
7548, 7605, 7606, 8339, 8813.

I'd like them to sort in true numeric ascending order like this: 1937, 1958,
2157, 2289, 2789, 2855, 5160, 5837, 7548, 7605, 7606, 8339, 8813, 13198,
13200, 13580, (with the ones with leading zeros to follow like this:) 01316,
01327, 01329, 02884, 02888, 02889 . . . 09999

I've searched these posts and several sites and can't find a good fit, but
surely someone else may have encountered a similar sort problem. AM too new
to programming to savy all this code so maybe someone more experienced can
steer me or add to this.

Any help muchas gracias!




Private Sub QuickSort(strArray() As String, intBottom As Integer, intTop As
Integer)

Dim strPivot As String, strTemp As String
Dim intBottomTemp As Integer, intTopTemp As Integer

intBottomTemp = intBottom
intTopTemp = intTop

strPivot = strArray((intBottom + intTop) \ 2)

While (intBottomTemp <= intTopTemp)

While (strArray(intBottomTemp) < strPivot And intBottomTemp < intTop)
intBottomTemp = intBottomTemp + 1
Wend

While (strPivot < strArray(intTopTemp) And intTopTemp intBottom)
intTopTemp = intTopTemp - 1
Wend

If intBottomTemp < intTopTemp Then
strTemp = strArray(intBottomTemp)
strArray(intBottomTemp) = strArray(intTopTemp)
strArray(intTopTemp) = strTemp
End If

If intBottomTemp <= intTopTemp Then
intBottomTemp = intBottomTemp + 1
intTopTemp = intTopTemp - 1
End If

Wend

'the function calls itself until everything is in good order
If (intBottom < intTopTemp) Then QuickSort strArray, intBottom, intTopTemp
If (intBottomTemp < intTop) Then QuickSort strArray, intBottomTemp, intTop

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default sort routine puts in wrong order

Try these changes:
Change strArray() As String to LongArray() As Long
Change strPivot As String to LongPivot As Long
While you are at it you might as well change all Integer to Long.

RBS


"owlnevada" wrote in message
...
I am attempting to modify this sort routine(which I didn't create) to sort
a
series of variable length string arrays using permit numbers correctly.
The
numbers that appear sort like this: 01316, 01327, 01329, 02884, 02888,
02889, 13198, 13200, 13580, 1937, 1958, 2157, 2289, 2789, 2855, 5160,
5837,
7548, 7605, 7606, 8339, 8813.

I'd like them to sort in true numeric ascending order like this: 1937,
1958,
2157, 2289, 2789, 2855, 5160, 5837, 7548, 7605, 7606, 8339, 8813, 13198,
13200, 13580, (with the ones with leading zeros to follow like this:)
01316,
01327, 01329, 02884, 02888, 02889 . . . 09999

I've searched these posts and several sites and can't find a good fit, but
surely someone else may have encountered a similar sort problem. AM too
new
to programming to savy all this code so maybe someone more experienced can
steer me or add to this.

Any help muchas gracias!




Private Sub QuickSort(strArray() As String, intBottom As Integer, intTop
As
Integer)

Dim strPivot As String, strTemp As String
Dim intBottomTemp As Integer, intTopTemp As Integer

intBottomTemp = intBottom
intTopTemp = intTop

strPivot = strArray((intBottom + intTop) \ 2)

While (intBottomTemp <= intTopTemp)

While (strArray(intBottomTemp) < strPivot And intBottomTemp < intTop)
intBottomTemp = intBottomTemp + 1
Wend

While (strPivot < strArray(intTopTemp) And intTopTemp intBottom)
intTopTemp = intTopTemp - 1
Wend

If intBottomTemp < intTopTemp Then
strTemp = strArray(intBottomTemp)
strArray(intBottomTemp) = strArray(intTopTemp)
strArray(intTopTemp) = strTemp
End If

If intBottomTemp <= intTopTemp Then
intBottomTemp = intBottomTemp + 1
intTopTemp = intTopTemp - 1
End If

Wend

'the function calls itself until everything is in good order
If (intBottom < intTopTemp) Then QuickSort strArray, intBottom,
intTopTemp
If (intBottomTemp < intTop) Then QuickSort strArray, intBottomTemp,
intTop

End Sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort Routine Platinum girl[_2_] Excel Discussion (Misc queries) 0 March 9th 07 03:21 PM
filted data, copy and paste a col. puts data in wrong row how fix chris_fig New Users to Excel 1 October 16th 06 04:26 PM
Drop-down list triggering the wrong routine Broadband Al Excel Programming 3 November 22nd 05 10:03 PM
IN EXCEL I HAVE A LIST I TRY SORT ASENDING BUT IT PUTS TRUE AFTER. DISCO DAVE Excel Discussion (Misc queries) 2 April 15th 05 06:36 PM
Sort Routine VBA weeper Excel Programming 2 September 29th 04 02:59 PM


All times are GMT +1. The time now is 07:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"