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]
SectionList; change order
-
- Site Admin
- Posts: 6394
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Reversing the sequence of sections in a SectionList
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
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
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.
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) {