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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ArraySort problems

Status
Not open for further replies.

plook

IS-IT--Management
Apr 1, 2000
33
Hi Dudes !

I've got a little problem using the ArraySort function in CF. I have two books saying opposite things regarding the way to use that function.

One way says that ArraySort returns a boolean value and the other book says that the value returned is an Array !!

So I tried both ways ...

<CFSET Variable_Never_Declared_Before = ArraySort(MyArray,&quot;textnocase&quot;,&quot;desc&quot;>

and

<CFSET MyArray = ArraySort(MyArray,&quot;textnocase&quot;,&quot;desc&quot;>

both give me the same error. So I declared a second Array, thinking maybe I cannot sort the array and put it in the same array after...

<CFSET MyArray2 = ArraySort(MyArray,&quot;textnocase&quot;,&quot;desc&quot;>

Same Error !!

Here is the long error message I got with all the previous attempts :

-------------------
The expression has requested a variable or an intermediate expression result as a simple value, however, the result cannot be converted
to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are
examples of complex values.

The most likely cause of the error is that you are trying to use a complex value as a simple one. For example, you may be trying to use a
query variable in a &amp;ltCFIF> tag. This was possible under Cold Fusion 2.0 but is an error under later versions.

The error occurred while evaluating the expression:

MyArray = ArraySort(MyArray,&quot;textnocase&quot;,&quot;desc&quot;)

The error occurred while processing an element with a general identifier of (CFSET), occupying document position (167:1) to (167:61)

------------------

Line 167 refers to the line in question..

Does anybody know what I am doing wrong here ?

This array is a two-dimension one if that matters !

Thanks a bunch in advance

Dominic
 
According to the code you posted, you're missing the closing &quot;)&quot; in your arraysort statement. From the error message though, I assume this is just a typo in your post.

The arraySort() function returns a boolean value but the array you give it to sort is sorted so you just need to assign the results to a temp variable like this and then reference the original array.

<cfset temp = ArraySort(MyArray,&quot;textnocase&quot;,&quot;desc&quot;)>

In your example, by using the syntax &quot;MyArray = ArraySort()&quot;, the array &quot;MyArray&quot; gets sorted first, the function then returns a &quot;yes&quot; and finally &quot;MyArray&quot; gets assigned this &quot;yes&quot; value. By using a temp varaible, you simply discard the boolean result code and then use &quot;MyArray&quot; which should be sorted.

Hope this helps,
GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top