SectionList; change order

The basics of how to develop, test, and use models.
Post Reply
thats_karlo
Posts: 108
Joined: Thu Sep 08, 2005 11:49 am

SectionList; change order

Post by thats_karlo »

Hi,

Do you have any idea how we can change the position of section in a SectionList.

suppose in forsec seclist1 {print secname()} gives this results

dend[10]
dend[9]
dend[4]
dend[3]
dend[1]


i like to have a new section list which give me this result,

forsec new_seclist1{print secname()}

dend[1]
dend[3]
dend[4]
dend[9]
dend[10]

thats_karlo
Posts: 108
Joined: Thu Sep 08, 2005 11:49 am

Post by thats_karlo »

HI!

There is no way for that!!!

this is why i didn't get any answer?

ted
Site Admin
Posts: 5769
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Reversing the sequence of sections in a SectionList

Post by ted »

The trick is to build an intermediate List of SectionRefs, then read backwards through that List.

Code: Select all

objref sr, templist
forsec oldseclist templist.append(new SectionRef())

// templist now contains SectionRefs in the same order as the sections in oldseclist

objref newseclist
newseclist = SectionList()
for (i=templist.count()-1; i>0; i=i-1) {
  templist.object(i).sec newseclist.append()
}
objref templist // destroy the List of SectionRefs, which is no longer needed

// newseclist has the same sections as oldseclist, but in reverse order

thats_karlo
Posts: 108
Joined: Thu Sep 08, 2005 11:49 am

Post by thats_karlo »

Hi Ted,


Wonderful!!! thank you so much

JimH
Posts: 54
Joined: Tue Apr 10, 2007 3:36 pm
Location: Duke University

Post by JimH »

Here are some of the code lines I modified, as well as an added explanation at the bottom which helped me understand better what was going on

Code: Select all

objref templist //sr not needed

Code: Select all

newseclist = new SectionList() //I got an error without "new" on MSwindows

Code: Select all

//Without "=" in ">=" one section was being dropped
for (i=templist.count()-1; i>=0; i=i-1) {
Unfortunately the SectionList does properties/functions (please excuse the loose terminology) like count or object, so instead the sectionList is put into a List (not a SectionList), and then back into a sectionList.

Post Reply