• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Sorting an array of structures in CF 7

New Here ,
Oct 02, 2009 Oct 02, 2009

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 !

TOPICS
Advanced techniques

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 03, 2009 Oct 03, 2009

Copy link to clipboard

Copied

Haven't you already asked this question?

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 05, 2009 Oct 05, 2009

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 05, 2009 Oct 05, 2009

Copy link to clipboard

Copied

SORRY !

TYPO !

The next command, which caused the error was:

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

>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 05, 2009 Oct 05, 2009

Copy link to clipboard

Copied

Whatever you tried to do, you tried to do to the entire array instead of the array element.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 05, 2009 Oct 05, 2009

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 05, 2009 Oct 05, 2009

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 !

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 06, 2009 Oct 06, 2009

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 06, 2009 Oct 06, 2009

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation