Skip to main content
Known Participant
October 2, 2009
Question

Sorting an array of structures in CF 7

  • October 2, 2009
  • 2 replies
  • 1345 views

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 !

This topic has been closed for replies.

2 replies

October 6, 2009

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...

GaryNYAuthor
Known Participant
October 6, 2009

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...

Inspiring
October 4, 2009

Haven't you already asked this question?

--

Adam

GaryNYAuthor
Known Participant
October 5, 2009

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.

GaryNYAuthor
Known Participant
October 5, 2009

SORRY !

TYPO !

The next command, which caused the error was:

<cfloop index="i" from="1" to="#ArrayLen(sortedKeysTD)#"

>