Copy link to clipboard
Copied
Hi !
I populated an array of structures from an invoked method- query loop:
(ind is increased in a loop)
<CFSET TD[ind] = StructNew()>
<cfset TD[ind].V1 = "#qryTermst.v1#">
<cfset TD[ind].V2 = "#qryTermst.v2#">
<cfset TD[ind].V3 = "#qryTermst.v3#">
<cfset TD[ind].D = "#DateFormat(qryTermst.date, 'M/D/YYYY')#">
<cfset TD[ind].V5 = "#qryTermst.v5#">
It looks fine and contains correct data.
After the array is populated- later - I need to display it in descending order of D (dates) and in ascending order of V1.
I tried to use the StructSort function, but did not get results in CF 7- strange errors...
Any help will be appreciated !
Regards !
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi !
First, I was not sure on which forum to post the question.
Second, it seems to be no easily answered, so it pays then to try more.
I tried to sort the array first:
<cfset sortedKeysTD = StructSort(TD, "text", "desc")>
Then I did the loop:
<cfloop index="i" from="1" to="#ArrayLen(TH)#">
When I try to run this (more or less simple code), I have an error:
You have attempted to dereference a scalar variable of type class coldfusion.runtime.Array as a structure with members.
Any thoughts ?
I will appreciate any ideas.
Gary.
Copy link to clipboard
Copied
SORRY !
TYPO !
The next command, which caused the error was:
<cfloop index="i" from="1" to="#ArrayLen(sortedKeysTD)#"
>
Copy link to clipboard
Copied
Whatever you tried to do, you tried to do to the entire array instead of the array element.
Copy link to clipboard
Copied
No harm done with cross-posting. But as a general rule, just pick one of the forums and if it's the wrong one (which unless your question is nothing to do with CF, is not likely to be the case), someone will let you know 😉 The reason not to cross-post is that it splits people's efforts in trying to help you, which could waste their time. And yours.
Anyway, did you investigate my response to you on the other thread? I have a strong feeling that that's your actual answer...
--
Adam
Copy link to clipboard
Copied
Yes, I solved the issue twice:
1. partially (1 key sort) - with arrays of structures- using shadow arrays
2. fully- much better- using query objects- any type of sort I want,
unions, etc.
Thank you !
Copy link to clipboard
Copied
Considering that you did not want to try http://www.cflib.org/udf/QuickSort as was suggested earlier, I do not know what to suggest...
Convert your array of structs to query object and run QoQ with your sort order...
Copy link to clipboard
Copied
You are correct- done this- works fine !
I should not waste my time with arrays of structures- not nicely supported
and straightforward as in PL/1, for example...