SitePoint Sponsor |
|
User Tag List
Results 1 to 11 of 11
Thread: Help with custom sorting
-
Oct 26, 2010, 14:11 #1
- Join Date
- Jul 2008
- Posts
- 74
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Help with custom sorting
Our site has many documents whose titles are indexed in this format:
1-1, 1-2, 1-2A, etc., 1-11, 1-12, 2-1, 2-2, 2-3A, 2-10, etc.
(The actual titles follow the format "Procedure 1-5 Smoking in the Workplace")
I've been trying to devise a custom sort in VBscript that will treat, say, 2-10 as numerically greater than 2-1. This would also mean that 10-1 would have to be greater than 2-1. I'm not necessarily looking for code examples, but mostly for sorting techniques to solve this problem.
-
Oct 26, 2010, 14:33 #2
- Join Date
- Jun 2007
- Posts
- 691
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
sorting these type of alphanumerics usually requires padding with zeroes - sorting - then stripping out the padding before display.
-
Oct 27, 2010, 04:10 #3
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Or break out the numeric portions as arrays of numeric (not text) element references and sort that way?
-
Oct 27, 2010, 07:08 #4
- Join Date
- Jul 2008
- Posts
- 74
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks. I looked around for ways to insert the zeros, but this seemed to involve trying to convert the numbers on both sides of the dash to integers, and it choked on instances such as 1-2A.
I just did some quick research and apparently VBscript has limited support for regular expressions, something I didn't realize. I'll see if this yields better results.
-
Oct 27, 2010, 15:04 #5
- Join Date
- Jul 2008
- Posts
- 74
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I have a tentative solution - I used VBScript's RegExp function to find the index number and then separate the index into three pieces. These I store as array elements for relatively easy comparison.
A shame that VBScript doesn't have support for associative arrays. I tried the Dictionary object a while back as a substitute, but with no luck.
-
Oct 27, 2010, 21:13 #6
- Join Date
- Apr 2009
- Posts
- 359
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Just a thought, perhaps you want to re-visit your db design. It appears the two halves of your data are two different things, maybe they should be in different columns in the data.
Doug G
=====
"If you ain't the lead dog, the view is always the same - Anon
-
Oct 28, 2010, 12:42 #7
- Join Date
- Jun 2007
- Posts
- 691
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
VBScript does use the dictionary object in lieu of associative arrays and it should work.
You can also use Javascript arrays since ASP supports other languages. You can even use them multiple languages on the same page.
A VBscript function can be called from Javascript and vice versa so there are many options to choose from for your solution.
-
Oct 29, 2010, 05:34 #8
- Join Date
- Jul 2008
- Posts
- 74
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
There's no database involved. The script simply reads the filenames in the directory. The old version used a bubble sort for alphabetical order, except that the indexing system didn't match alphanumeric sorting.
Strange that on the Windows server I'm using, I can open up the directory in a window, click the Name bar to sort the files, and they will be the order that I want. It's as if Windows and VBScript's strcomp function use different rules for alphanumeric sorting. (And I tried both binary and textual comparison for the latter.)
-
Oct 29, 2010, 10:18 #9
- Join Date
- Jul 2005
- Location
- West Springfield, Massachusetts
- Posts
- 17,290
- Mentioned
- 198 Post(s)
- Tagged
- 3 Thread(s)
Is the Windows OS using the juliet filenames (8 characters max)?
Big Change Coming Soon - if you want your PMs save them now!
What you need to do to prepare for our migration to Discourse
A New SitePoint Forum Experience: Our Move to Discourse
-
Oct 29, 2010, 13:19 #10
- Join Date
- Jul 2008
- Posts
- 74
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Oct 29, 2010, 14:13 #11
- Join Date
- Apr 2009
- Posts
- 359
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
There's no database involved. The script simply reads the filenames in the directory. The old version used a bubble sort for alphabetical order, except that the indexing system didn't match alphanumeric sorting
Another thought, I haven't used the filesystem object in years but it offers the ability to traverse through directory/file names. Perhaps using it to list the filenames would take advantage of the proper sorting done by windows explorer? Just a total guess.Doug G
=====
"If you ain't the lead dog, the view is always the same - Anon
Bookmarks