ASP
  Home arrow ASP arrow Page 3 - How to Sort a Multi-Dimensional Array
IBM developerWorks
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

How to Sort a Multi-Dimensional Array
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 53
    2004-06-09

    Table of Contents:
  • How to Sort a Multi-Dimensional Array
  • A Quick Explanation of the Multi-Dimensional Array Function
  • And We Proceed with Our Checking
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th -1:00PM EST. Register Today!

    How to Sort a Multi-Dimensional Array - And We Proceed with Our Checking


    (Page 3 of 4 )

    If we have genuine dates, we proceed with our checking, by using the ASP dateDiff() function. Similar to strComp(), this function produces positive or negative integers; however, they're based on the difference in the time frame you specify, and we will specify days (“d”).

    if not isDate( smallestValue ) then
    arraySort = arraySort( arToSort, sortBy, false)
    exit function
    else

    if dateDiff( "d", arToSort( sortBy, d ), smallestValue ) > 0 Then '=== no carriage return

    smallestValue = arToSort( sortBy, d )
    smallestIndex = d

    End if
    end if
    end if
    Next

    Now, we're finished checking the whole array for this specific item, and before we move on the next, we see if anything smaller has been found. If so, then we'll swap the current item for the smallest item found. And of course, since we're dealing with multiple dimensions, we have to loop through them all, and swap all of them, to make sure that we maintain the complete array.

    if smallestIndex <> c Then
    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
    arraySort = arToSort
    end function

    More ASP Articles
    More By Justin Cook


       · You state:Ok, so let's assume that we have an array that looks like...
     

    ASP ARTICLES

    - ADO for the Beginner
    - ADO.NET 101: Data Rendering with a DataGrid ...
    - Introducing SoftArtisans OfficeWriter 3.0 En...
    - Getting Remote Files With ASP
    - The Real Basics of Functions in ASP
    - Enhancing Readability with ASP
    - Mimicking PHP's String Formatting Functions
    - Windows Server Hacks 12, 77, and 98
    - How to Sort a Multi-Dimensional Array
    - Developing an Information Management Tool wi...
    - What are Active Server Pages?
    - Getting Remote Pages with ASP
    - FTP’ing Files with ASP
    - Apply Single-Sign-On to Your Application
    - Easy Error Management

    Iron Speed




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway