A generic stable indexed data sorting class

Submitted on: 2/15/2015 5:07:00 AM
By: Rde (from psc cd)  
Level: Intermediate
User Rating: By 14 Users
Compatibility: VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 4516
     With this generic solution you can sort any data that is stored in an indexed data storage structure such as lists, collections, and arrays of all data types, including multi-dimensional arrays and arrays of UDTs ... Three methods are demonstrated - Event raising WithEvents, an Implemented callback, and a clever CallWindowProc technique I picked up from LukeH (selftaught) ... The Implemented callback method is almost twice as fast as the Event raising method, and is also slightly faster than the CallWindowProc method ... This is a complete solution that allows you to cancel sorting within the Compare routine, and also a progress parameter that indicates the percentage completed as a long value of 1 to 100. These features are included in the demo ... Update 21 Feb 2008 tweaked a little speed and attempted to create a level performance test between the CWP method and the other two - now just a few 100ths of a second behind the Implemented method ... Obscure Bug Fix 7 March 09. I documented they 'can sort sub-sets of the array data' but with these indexed versions if you do an error *could* occur without this very small change.

This article has accompanying files


Generic Sorting Classes

You can sort any data that is stored in an indexed data storage structure such as lists, collections, and arrays of all data types, including multi-dimensional arrays and arrays of UDTs.

It is up to you to write the comparison code needed in the exposed Compare routine to suit your particular storage structure and data type.

This is actually the best approach as it hides all the sorting details and leaves you to handle only the comparison code relavant to your current data implementation and desired sort criteria.

This is not intended to be a treatise on sorting multi-dimensional arrays or arrays of UDT's, if this is what you need then psc has has some very good examples on these subjects.

This is intended as a straighforward sorting solution that may be useful if you have a specific need to sort an indexed data structure, and you would like the sorting details to be hidden, and the sorting class's usage to be as simple and as generic as possible.

Each class header has clear instructions on how to implement that particular solution, and this form's code also demonstrates the usage of each sorting class without complicating it with data implementation details.

Free Usage

As usual, you are free to use any part or all of this code even for commercial purposes in any way you wish under the one condition that no copyright notice is moved or removed from where it is.

Happy coding :)


winzip iconDownload article

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net

Other 30 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

9/13/2018 6:57:42 AMLorin

How about a BinarySearch method for the resultant Indexed sorted data ?

(If this comment was disrespectful, please report it.)


Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)

To post feedback, first please login.