Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ArraySort - I need another pair of eyes. 1

Status
Not open for further replies.

calista

Programmer
Jan 24, 2001
545
US
What's wrong, here? Everything is fine down to the ArraySort. As you can see, I test DocTypeArray to make sure it is an array and contains what I think it does. It tests "true" as an array, and it does contain the right data. When I try to sort the array, I don't get an error on the sort, but SortedDocArray tests "no" as an array.

I've tried every permutation I can think of,including declaring SortedDocArray before the sort,quotes and no quotes, ## and no ## , etc., but I get the same result. What am I missing?
Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<HTML>
<HEAD>
	<TITLE>Test Query</TITLE>
</HEAD>

<BODY>
<CFPARAM NAME=&quot;DocNameList&quot; DEFAULT=&quot;&quot;>
<!--- Here is the list. --->
<CFSET DOCTYPELIST = &quot;1,2,3,4,7,10,11&quot;>
<BR>
<!--- Now, I am creating a list of the DocType names. --->
<CFLOOP INDEX=&quot;DocTypeIndex&quot; LIST=&quot;#DocTypeList#&quot;>
		<CFQUERY NAME=&quot;GetDocTypes&quot;
       				DATASOURCE=&quot;#Application.Datasource#&quot;
       				DBTYPE=&quot;ODBC&quot;>
				SELECT *
				FROM DocTypeTable
				WHERE DocTypeID = #DocTypeIndex#
		</CFQUERY>
		<CFOUTPUT QUERY=&quot;GetDocTypes&quot;>#DocType#<BR></CFOUTPUT>
		<CFSET DocNameList = #ListAppend(DocNameList,GetDocTypes.DocType)#>
</CFLOOP>
<BR><BR>
<CFOUTPUT>#DocNameList#</CFOUTPUT>
<BR><BR>
<!--- Create an array. --->
<CFSET DocTypeArray = #ArrayNew(1)#>
<!--- Convert list to array. --->
<CFSET DocTypeArray = #ListToArray(DocNameList)#>
<CFIF #IsArray(DocTypeArray)# EQ &quot;Yes&quot;>
	DocTypeArray is an Array.<BR><BR>
<CFELSE>
	DocTypeArray is NOT an array.<BR><BR>
</CFIF>
<CFLOOP INDEX=&quot;ArrayIndex&quot; FROM=&quot;1&quot; TO=&quot;7&quot; STEP=&quot;1&quot;>
	<CFOUTPUT>#DocTypeArray[ArrayIndex]#<BR></CFOUTPUT>
</CFLOOP>
<BR><BR>
<!--- Sort the array. --->
<CFSET SortedDocArray = ArraySort(DocTypeArray,&quot;textnocase&quot;,&quot;asc&quot;)>
<CFIF #IsArray(SortedDocArray)# EQ &quot;Yes&quot;>
	SortedDocArray is an Array.<BR><BR>
<CFELSE>
	SortedDocArray is NOT an array.<BR><BR>
</CFIF>
<!---
<CFOUTPUT>#SortedDocArray[1]#</CFOUTPUT><BR><BR>
<!--- Convert the array back to a list. --->
<CFSET SortedDocList = #ArrayToList(SortedDocArray)#>
<CFOUTPUT>#SortedDocList#</CFOUTPUT><BR><BR>
--->

</BODY>
</HTML>
Calista :-X
Jedi Knight,
Champion of the Force
 
Using ArraySort doesn't return an array, it return a Boolean value. If the ArraySort is successful ArraySort returns the value &quot;Yes&quot;. If not, ArraySort returns the value &quot;No&quot;.

So
<CFSET SortedDocArray = ArraySort(DocTypeArray,&quot;textnocase&quot;,&quot;asc&quot;)>
is like putting
<CFSET SortedDocArray = &quot;Yes|No&quot;>

If you want to put the sorted array into a 2nd array, you need to do it this way:
<!--- Copy the array from DocTypeArray to SortedDocArray --->
<CFSET SortedDocArray = DocTypeArray>

<!--- Either of the following 2 methods will sort the array SortedDocArray --->
<CFSET ArraySort(SortedDocArray,&quot;textnocase&quot;,&quot;asc&quot;)>
or
<CFSET tempVar = ArraySort(SortedDocArray,&quot;textnocase&quot;,&quot;asc&quot;)> - tleish
 
Thank you! When in doubt, read the directions, huh? :~/ Calista :-X
Jedi Knight,
Champion of the Force
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top