<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: ASP: Sort a Multi-Dimensional Array</title>
	<atom:link href="http://www.justin-cook.com/wp/2006/03/14/asp-sort-a-multi-dimensional-array/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.justin-cook.com/wp/2006/03/14/asp-sort-a-multi-dimensional-array/</link>
	<description>A web, technology, programming and SEO blog by Justin Cook</description>
	<lastBuildDate>Wed, 10 Mar 2010 21:22:18 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jason</title>
		<link>http://www.justin-cook.com/wp/2006/03/14/asp-sort-a-multi-dimensional-array/comment-page-1/#comment-154994</link>
		<dc:creator>Jason</dc:creator>
		<pubDate>Fri, 10 Apr 2009 17:51:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.justin-cook.com/wp/2006/03/15/asp-sort-a-multi-dimensional-array/#comment-154994</guid>
		<description>I think I&#039;m running into the same problem as linx. I get a &quot;type mismatch&quot; error when I do eventArray=arraySort(eventArray,1,true)

Any suggestions?</description>
		<content:encoded><![CDATA[<p>I think I&#039;m running into the same problem as linx. I get a &#034;type mismatch&#034; error when I do eventArray=arraySort(eventArray,1,true)</p>
<p>Any suggestions?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: linx</title>
		<link>http://www.justin-cook.com/wp/2006/03/14/asp-sort-a-multi-dimensional-array/comment-page-1/#comment-143907</link>
		<dc:creator>linx</dc:creator>
		<pubDate>Thu, 04 Sep 2008 11:51:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.justin-cook.com/wp/2006/03/15/asp-sort-a-multi-dimensional-array/#comment-143907</guid>
		<description>why  it returns error when 

       arTest = arraySort(arTest,1,true) 

is called :(

code------------------------

function arraySort( arToSort, sortBy, compareDates )


        Dim c, d, e, smallestValue, smallestIndex, tempValue
       
        For c = 0 To uBound( arToSort, 2 ) - 1
                &#039;&#039;=== set smallest to current
                smallestValue = arToSort( sortBy, c )
                smallestIndex = c
                For d = c + 1 To uBound( arToSort, 2 ) &#039;&#039;=== find smallest and set
                        if not compareDates then
                                if strComp( arToSort( sortBy, d ), smallestValue )  0 Then
                                                smallestValue = arToSort( sortBy, d )
                                                smallestIndex = d
                                        End if
                                end if
                        end if
                Next
               
                if smallestIndex  c Then &#039;&#039;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
        arraySort = arToSort
end function


dim arTest(2,2)
arTest(0, 0) = 1
arTest(0, 1) = &quot;01-01-2004&quot;
arTest(0, 2) = &quot;Event #1&quot;
arTest(1, 0) = 2
arTest(1, 1) = &quot;10-01-2005&quot;
arTest(1, 2) = &quot;Event #2&quot;
arTest(2, 0) = 3
arTest(2, 1) = &quot;02-01-2006&quot;
arTest(2, 2) = &quot;Event #3&quot; 

arTest = arraySort(arTest,1,true)

For i=LBound(arTest,1) to UBound(arTest,1)
	For j=LBound(arTest,2) to UBound(arTest,2)
		response.write(arTest(i,j) &amp; &quot; &quot;)
	next
	if j mod 3 = 0 then response.write(&quot;  &quot;)
next</description>
		<content:encoded><![CDATA[<p>why  it returns error when </p>
<p>       arTest = arraySort(arTest,1,true) </p>
<p>is called <img src='http://www.justin-cook.com/wp/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>code&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>function arraySort( arToSort, sortBy, compareDates )</p>
<p>        Dim c, d, e, smallestValue, smallestIndex, tempValue</p>
<p>        For c = 0 To uBound( arToSort, 2 ) &#8211; 1<br />
                &#034;=== set smallest to current<br />
                smallestValue = arToSort( sortBy, c )<br />
                smallestIndex = c<br />
                For d = c + 1 To uBound( arToSort, 2 ) &#034;=== find smallest and set<br />
                        if not compareDates then<br />
                                if strComp( arToSort( sortBy, d ), smallestValue )  0 Then<br />
                                                smallestValue = arToSort( sortBy, d )<br />
                                                smallestIndex = d<br />
                                        End if<br />
                                end if<br />
                        end if<br />
                Next</p>
<p>                if smallestIndex  c Then &#039;&#039;swap<br />
                        For e = 0 To uBound( arToSort, 1 )<br />
                                tempValue = arToSort( e, smallestIndex )<br />
                                arToSort( e, smallestIndex ) = arToSort( e, c )<br />
                                arToSort( e, c ) = tempValue<br />
                        Next<br />
                End if</p>
<p>        Next<br />
        arraySort = arToSort<br />
end function</p>
<p>dim arTest(2,2)<br />
arTest(0, 0) = 1<br />
arTest(0, 1) = &#034;01-01-2004&#034;<br />
arTest(0, 2) = &#034;Event #1&#034;<br />
arTest(1, 0) = 2<br />
arTest(1, 1) = &#034;10-01-2005&#034;<br />
arTest(1, 2) = &#034;Event #2&#034;<br />
arTest(2, 0) = 3<br />
arTest(2, 1) = &#034;02-01-2006&#034;<br />
arTest(2, 2) = &#034;Event #3&#034; </p>
<p>arTest = arraySort(arTest,1,true)</p>
<p>For i=LBound(arTest,1) to UBound(arTest,1)<br />
	For j=LBound(arTest,2) to UBound(arTest,2)<br />
		response.write(arTest(i,j) &amp; &#034; &#034;)<br />
	next<br />
	if j mod 3 = 0 then response.write(&#034;  &#034;)<br />
next</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Justin Cook</title>
		<link>http://www.justin-cook.com/wp/2006/03/14/asp-sort-a-multi-dimensional-array/comment-page-1/#comment-8283</link>
		<dc:creator>Justin Cook</dc:creator>
		<pubDate>Mon, 29 Jan 2007 14:02:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.justin-cook.com/wp/2006/03/15/asp-sort-a-multi-dimensional-array/#comment-8283</guid>
		<description>You should make sure that the &#039;score&#039; is a valid integer (maybe use cInt()), otherwise it may be comparing them as strings, which would account for the wonky sort results</description>
		<content:encoded><![CDATA[<p>You should make sure that the &#039;score&#039; is a valid integer (maybe use cInt()), otherwise it may be comparing them as strings, which would account for the wonky sort results</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 2.832 seconds -->
