Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Community Discussions (All other subjects)
 Sorting Characters
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

GauravBhabu
Advanced Member

4288 Posts

Posted - 26 November 2002 :  17:46:43  Show Profile
What is the criteria for sorting characters.

Example:

GauravBhabu

If is to be written in ascending order by characters how it should be written


  • Sorted by Asc Value


    • BGaaabhruuv


  • Sorted alphabetically and by Asc Value


    • aaaBbGhruuv







ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 26 November 2002 :  20:44:54  Show Profile  Send ruirib a Yahoo! Message
I guess that depends on the purpose of the sort, no? For a "general purpose" sort I would go with the second.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 26 November 2002 :  21:12:48  Show Profile
I am developing a module to sort values in an array, so looking for ideas/views. Inspired by discussion in the topic --- http://forum.snitz.com/forum/topic.asp?TOPIC_ID=38832
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 26 November 2002 :  21:35:25  Show Profile  Send ruirib a Yahoo! Message
I'd say you should make your function/sub configurable. Accept a parameter to choose which strategy to use, that will increase its usefulness...


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 26 November 2002 :  21:43:57  Show Profile
Okay! Thanks
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 26 November 2002 :  21:47:02  Show Profile  Send ruirib a Yahoo! Message
You're welcome .


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

Gremlin
General Help Moderator

New Zealand
7528 Posts

Posted - 26 November 2002 :  22:11:38  Show Profile  Visit Gremlin's Homepage
4Guys have several good articles on Sorting, I just grab one of their examples whenever I need one using a field passed to the sort to determine whether text or numeric is being sorted and whether its a forwards ot backwards sort. Something like this

(This read a directory list via FSO and just sorts it basically)


<%
' In this demo, at least, we don't allow user to change directories...
' Change the DIRECTORY to point to any virtual directory of your choice.
CONST DIRECTORY = "/images/EQMaps/" ' relative path in virtual directories

' Specify one of these constants for "sortBy"...
CONST FILE_NAME = 0
'CONST FILE_EXT = 1
CONST FILE_TYPE = 1
CONST FILE_SIZE = 2
CONST FILE_CREATED = 3
'CONST FILE_MODIFIED = 5
'CONST FILE_ACCESSED = 6

' get requested sort order, if not first time here...
' (forward by name is default)
req = Request("sortBy")
If Len(req) < 1 Then sortBy = 0 Else sortBy = CInt(req)
req = Request("priorSort")
If Len(req) < 1 Then priorSort = -1 Else priorSort = CInt(req)

'
' did user ask for same sort? to reverse the order?
' but if so, then zap priorSort so clicking again will do forward!
If sortBy = priorSort Then
    reverse = true
    priorSort = -1
Else
    reverse = false
    priorSort = sortBy
End If

' now start the *real* code...
'
path = Server.MapPath( DIRECTORY )

Set fso = CreateObject("Scripting.FileSystemObject")
Set theCurrentFolder = fso.GetFolder( path ) 
Set curFiles = theCurrentFolder.Files 
'
' And now a loop for the files
'
Dim theFiles( )
ReDim theFiles( 500 ) ' arbitrary size!
currentSlot = -1 ' start before first slot

' We collect all the info about each file and put it into one
' "slot" in our "theFiles" array. 
'
For Each fileItem in curFiles
    fname = fileItem.Name
    'fext = InStrRev( fname, "." )
    'If fext < 1 Then fext = "" Else fext = Mid(fname,fext+1)
    ftype = fileItem.Type
    fsize = fileItem.Size
    fcreate = fileItem.DateCreated
    'fmod = fileItem.DateLastModified
    'faccess = fileItem.DateLastAccessed
    currentSlot = currentSlot + 1
    If currentSlot > UBound( theFiles ) Then
        ReDim Preserve theFiles( currentSlot + 99 )
    End If
    ' note that what we put here is an array!
    'theFiles(currentSlot) = Array(fname,fext,ftype,fsize,fcreate,fmod,faccess)
    theFiles(currentSlot) = Array(fname,ftype,fsize,fcreate)
Next
'
' files are now in the array...
'
' As noted, it is actually an ARRAY *OF* ARRAYS. Which makes
' picking the column we will sort on easier!
'
' ...size and sort it...
fileCount = currentSlot ' actually, count is 1 more, since we start at 0
ReDim Preserve theFiles( currentSlot ) ' really not necessary...just neater!

' First, determine which "kind" of sort we are doing.
' (VarType=8 means "string")
'
If VarType( theFiles( 0 )( sortBy ) ) = 8 Then 
    If reverse Then kind = 1 Else kind = 2 ' sorting strings...
Else
    If reverse Then kind = 3 Else kind = 4 ' non-strings (numbers, dates)
End If

'
' A simple bubble sort for now...easier to follow the code...
'
For i = fileCount TO 0 Step -1
    minmax = theFiles( 0 )( sortBy )
    minmaxSlot = 0
    For j = 1 To i
        Select Case kind ' which kind of sort are we doing?
        ' after the "is bigger/smaller" test (as appropriate), 
        ' mark will be true if we need to "remember" this slot...
        Case 1 ' string, reverse...we do case INsensitive!
            mark = (strComp( theFiles(j)(sortBy), minmax, vbTextCompare ) < 0)
        Case 2 ' string, forward...we do case INsensitive!
            mark = (strComp( theFiles(j)(sortBy), minmax, vbTextCompare ) > 0)
        Case 3 ' non-string, reverse ...
            mark = (theFiles( j )( sortBy ) < minmax)
        Case 4 ' non-string, forward ...
            mark = (theFiles( j )( sortBy ) > minmax)
        End Select
        ' so is the current slot bigger/smaller than the remembered one?
        If mark Then 
            ' yep, so remember this one instead!
            minmax = theFiles( j )( sortBy )
            minmaxSlot = j
        End If
    Next
    ' is the last slot the min (or max), as it should be?
    If minmaxSlot <> i Then 
        ' nope...so do the needed swap...
        temp = theFiles( minmaxSlot )
        theFiles( minmaxSlot ) = theFiles( i )
        theFiles( i ) = temp
    End If
Next
' Ta-da! The array is sorted!
'
%>

Kiwihosting.Net - The Forum Hosting Specialists
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 27 November 2002 :  03:46:39  Show Profile
I like the one here by Doug G

http://forum.snitz.com/forum/topic.asp?TOPIC_ID=38832#199074
Go to Top of Page

Gremlin
General Help Moderator

New Zealand
7528 Posts

Posted - 27 November 2002 :  05:16:48  Show Profile  Visit Gremlin's Homepage
Me too, Hadn't thought of doing it like that myself :)

Kiwihosting.Net - The Forum Hosting Specialists
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.38 seconds. Powered By: Snitz Forums 2000 Version 3.4.07