Web Design and Development Forums

[SOLVED] Array sorting

This is a discussion on "[SOLVED] Array sorting" within the ASP Forum section. This forum, and the thread "[SOLVED] Array sorting are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > ASP Forum

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Nov 23rd, 2007, 08:36   #1 (permalink)
Section Manager -
Website Critique
 
welshstew's Avatar
 
Join Date: May 2007
Location: inside the outside
Posts: 1,094
Blog Entries: 10
[SOLVED] Array sorting

I am still learning ASP functions, so please be gentle with me. I have got a script that sorts a multi-dimensional array Ascending, but I need to switch this to Descending.

Anyway, I've gone and got myself all confuddled, and can't see the wood for the trees. Any help is hugely appreciated.

Code: Select all
Function arraySortDecend( arToSort, sortBy, compareDates )

    Dim c, d, e, smallestValue, smallestIndex, tempValue

    For c = 0 To uBound( arToSort, 2 ) - 1

        smallestValue = arToSort( sortBy, c )
        smallestIndex = c

        For d = c + 1 To uBound( arToSort, 2 )
            if not compareDates then
                if strComp( arToSort( sortBy, d ), smallestValue ) < 0 Then
                smallestValue = arToSort( sortBy, d )
                smallestIndex = d
                End if
            else
                if not isDate( smallestValue ) then
                    arraySort = arraySort( arToSort, sortBy, false)
                    exit function
                else
                    if dateDiff( "d", arToSort( sortBy, d ), smallestValue ) > 0 Then
                        smallestValue = arToSort( sortBy, d )
                        smallestIndex = d
                    End if
                end if
            end if
        Next

        if smallestIndex <> c Then 'swap
            For e = 0 To uBound( arToSort, 1 )
                tempValue = arToSort( e, smallestIndex )
                arToSort( e, smallestIndex ) = arToSort( e, c )
                arToSort( e, c ) = tempValue
            Next
        End if
    Next
    End Function
__________________
WelshStew
Section Manager

tierney rides tboard - uk site : xtreme wales - extreme clothing

Last edited by welshstew; Nov 23rd, 2007 at 08:37. Reason: no asp tag for code...
welshstew is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Nov 27th, 2007, 00:03   #2 (permalink)
Most Reputable Member
 
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,567
Blog Entries: 2
Send a message via Yahoo to Monie
Re: Array sorting

Sorry welshstew, I don't know array in asp I am new to asp as well..
Maybe Eran can help?
__________________

Monie is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Nov 27th, 2007, 18:06   #3 (permalink)
Junior Member
 
Join Date: Aug 2007
Location: Haverhill
Posts: 40
Re: Array sorting

You say your code currently sorts the array ascending

I believe but have not checked nor properly read your code that the following modified code will work.

Code: Select all
Function arraySortDecend( arToSort, sortBy, compareDates )
    Dim c, d, e, smallestValue, smallestIndex, tempValue
    For c = 0 To uBound( arToSort, 2 ) - 1
        smallestValue = arToSort( sortBy, c )
        smallestIndex = c
        For d = c + 1 To uBound( arToSort, 2 )
            if not compareDates then
                if strComp( smallestValue, arToSort( sortBy, d ) ) < 0 Then
                smallestValue = arToSort( sortBy, d )
                smallestIndex = d
                End if
            else
                if not isDate( smallestValue ) then
                    arraySort = arraySort( arToSort, sortBy, false)
                    exit function
                else
                    if dateDiff( "d", smallestValue, arToSort( sortBy, d ) ) > 0 Then
                        smallestValue = arToSort( sortBy, d )
                        smallestIndex = d
                    End if
                end if
            end if
        Next
        if smallestIndex <> c Then 'swap
            For e = 0 To uBound( arToSort, 1 )
                tempValue = arToSort( e, smallestIndex )
                arToSort( e, smallestIndex ) = arToSort( e, c )
                arToSort( e, c ) = tempValue
            Next
        End if
    Next
    End Function
I cannot stress enough that this is just my cursory glance at it.

Personally when I am trying to create a piece of code I start out writing out how I would do it manually in simple english then work on converting that to code with some refinements along the way.
I find that it helps my understanding of what I'm doing.
Phil is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Nov 28th, 2007, 13:56   #4 (permalink)
Junior Member
 
Join Date: Oct 2007
Location: Israel
Age: 20
Posts: 31
Re: Array sorting

i found his code on google as a step by step guide thats explain what every row doing and where you need to change the code to Descending.
I can do it to but i need to run some tests to check if its work and i`m kinda lazzy :P
you can make a new array and get all the asc array to there one by one in a loop or you can loop the array backwards... or you can find and read the script writer guide.
Eran is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Nov 28th, 2007, 14:07   #5 (permalink)
Section Manager -
Website Critique
 
welshstew's Avatar
 
Join Date: May 2007
Location: inside the outside
Posts: 1,094
Blog Entries: 10
Re: Array sorting

Thanks for the help guys, will check the script writier guide, if you could point a link to me.

Thanks again.

Stew
__________________
WelshStew
Section Manager

tierney rides tboard - uk site : xtreme wales - extreme clothing
welshstew is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Nov 28th, 2007, 15:50   #6 (permalink)
Junior Member
 
Join Date: Oct 2007
Location: Israel
Age: 20
Posts: 31
Re: Array sorting

http://www.aspfree.com/c/a/ASP/How-t...nsional-Array/


http://www.aspfree.com/c/a/ASP-Code/...nders-Franzen/

Last edited by Eran; Nov 28th, 2007 at 15:52.
Eran is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Nov 28th, 2007, 16:45   #7 (permalink)
Section Manager -
Website Critique
 
welshstew's Avatar
 
Join Date: May 2007
Location: inside the outside
Posts: 1,094
Blog Entries: 10
Re: Array sorting

Thanks Eran, I think I have it sorted now. At least it is working for me at the mo.

Code: Select all
Function arraySortDecend( arToSort, sortBy, compareDates )

    Dim c, d, e, smallestValue, smallestIndex, tempValue

    'loops the array
    For c = 0 To uBound( arToSort, 2 ) - 1
        'assign current value as smallest value
        smallestValue = arToSort( sortBy, c )
        smallestIndex = c
        'next array item
        For d = c + 1 To uBound( arToSort, 2 )
            if not compareDates then
                'take this item and compare to previous item
                if strComp( arToSort( sortBy, d ), smallestValue ) < 0 Then
                'grab the smallest value
                smallestValue = arToSort( sortBy, d )
                smallestIndex = d
                End if
            else
                if not isDate( smallestValue ) then
                    arraySort = arraySort( arToSort, sortBy, false)
                    exit function
                else
                    if dateDiff( "d", smallestValue, arToSort( sortBy, d ) ) > 0 Then
                        smallestValue = arToSort( sortBy, d )
                        smallestIndex = d
                    End if
                end if
            end if
        Next

        if smallestIndex <> c Then 'swap the index
            For e = 0 To uBound( arToSort, 1 )
                tempValue = arToSort( e, smallestIndex )
                arToSort( e, smallestIndex ) = arToSort( e, c )
                arToSort( e, c ) = tempValue
            Next
        End if
    Next
    End Function
and then this is the array sort parameter:

Code: Select all
'sort the array
    arraySortDecend pressReleases, 2, true
Thanks all for the help.

Stew
__________________
WelshStew
Section Manager

tierney rides tboard - uk site : xtreme wales - extreme clothing
welshstew is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
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 On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] array woes eon201 PHP Forum 1 Nov 6th, 2007 15:13
[SOLVED] PHP Sorting Stuart PHP Forum 10 Oct 20th, 2007 00:46
Sorting a PHP array fallen_angel PHP Forum 3 Apr 20th, 2007 22:18
Sorting a new array from an existing array Ozeona Flash & Multimedia Forum 2 Sep 20th, 2005 08:43
Sorting the array - reversing the sequence codes? Ozeona Flash & Multimedia Forum 1 Aug 3rd, 2005 01:52



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 13:28.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59