PC Review


Reply
Thread Tools Rate Thread

Build a String Sort Key, sort a 2 dimen array Mar20

 
 
Neal Zimm
Guest
Posts: n/a
 
      20th Mar 2010
Hi All, Mar20
I'm building a utility function that sorts the rows of a 2 dimen
array on any up to all of its columns, (ascending or descending by wanted
column.) My 'first' version is working fine.

I'm enhancing the first version which handled only positive integer
and long data types, and string values to include + or - decimal numbers.
(e.g. for dates I use CStr and CDbl to create a string serial date number
40359.75123) The logic to align #'s with different quantities of decimals,
1.2
versus 1.12345 is coming along.

My problem is picking a 'best' way to still have numbers sort 'lower'
than alpha, while still being able to choose a binary or text comparison.

Background: the key is below, (spaces are for illustration here, (wish we
could post here in a non-proportional font) Let "s" = 1 space, other letters
are string values. Digits and the "." and "-" are themselves.
Below is a 3 column example of the key string for 4 array rows prior to
sorting the keys.

xywzsss xxxx 666 1 these keys have a Len of 15.
-123.00 DEfg 999 2 (rightmost 1-4 are the input 2 dim array row#'s
s000.55 aaaa 888 3 used to rewrite the input after the keys are
-123.00 defg 888 4 sorted.)

The key sequence after the ascending key sort should be row 4 first,
row 2 second, row 3 third, and row 1 last.

1. I need to get neg #'s to sort before positive. I used the ~ character,
(the sedilla ?) instead of the s in the .55 row 3 string, because a space
sorts before a - sign, BUT a vbTextCompare sort did NOT sort the ~ as
expected. A binary comparsison worked for that, but a binary compare does
not give desired results when sorting on alpha strings ("de" came after
"DE")

2. I think I have to enlarge the key when a column in the array has both
negative and positive numbers and string data. (I examine the sorting columns
in all rows of the input array to pick up their characteristics prior to
building
the keys.) lead character for string data = z negative # = N, positive #
= P

2a. For the leftmost data above, the 'new' key part would look like:
zxywzsss I think this gets me the sequence I want
N123.00s for either a text or binary comparison on
P000.55s the entire key.
N123.00s

Any suggestions would be most helpful. Thanks.

Neal

--
Neal Zimm
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using IComparer to Sort a String Array Jeta Microsoft C# .NET 8 27th Mar 2008 03:21 PM
NETCF - Array.Sort Method (Array, IComparer) - error aprivate Microsoft VB .NET 3 10th May 2005 02:16 PM
Re: sort (on part of) string - originally posted under Tricky Sort Tom Ogilvy Microsoft Excel Programming 0 6th Aug 2004 02:42 AM
Maintain initial sort order with 2d array sort Bob Dankert Microsoft C# .NET 3 11th May 2004 02:32 AM
sort string array Leanne Microsoft Access Form Coding 1 7th Oct 2003 12:51 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:26 PM.