Sort List Fields
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Sort List Fields
I have two list fields.
When I sort field f2 I want field f1 to be
sorted in the same order.
Stack attached.
When I sort field f2 I want field f1 to be
sorted in the same order.
Stack attached.
- Attachments
-
- List Sort.zip
- (1.4 KiB) Downloaded 221 times
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
Re: Sort List Fields
I must be missing something incredibly obvious here, but I'm not sure I get the question. Field 1 has whole numbers, field 2 has fractional components.
*Edit - just in case you just wanted them sorted, which I seriously doubt, you could try this -
Do you mean you want field 1 sorted with tabs instead of commas? In columns instead of lines? Something else?*Edit - just in case you just wanted them sorted, which I seriously doubt, you could try this -
Code: Select all
on mouseUp
set itemDel to comma
sort lines of field f1 ascending numeric by word 1 of each
end mouseUp
Last edited by bogs on Mon Aug 27, 2018 1:18 am, edited 1 time in total.
Re: Sort List Fields
Field 2 shows the stdDev and avgDev of the
sets of numbers in field 1 so when the deviations
are sorted I want the number sets to be in the
same order.
sets of numbers in field 1 so when the deviations
are sorted I want the number sets to be in the
same order.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
-
- VIP Livecode Opensource Backer
- Posts: 9665
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Sort List Fields
Ross.
I also do not understand your question. The short script you have in btn "sort f1" does exactly what you ask it. The entire field is sorted numeric.
Is it that you want to isolate and sort the lines individually, line by line, and not as a "group"?
Craig Newman
I also do not understand your question. The short script you have in btn "sort f1" does exactly what you ask it. The entire field is sorted numeric.
Is it that you want to isolate and sort the lines individually, line by line, and not as a "group"?
Craig Newman
Re: Sort List Fields
No, I think the request is for a sort that correlates the index of field 1 with field 2. So when the sort order changes in field 2, the lines of field 1 change sort order to match.
I'd play with this more but on phone, away on hols.
I'd play with this more but on phone, away on hols.
Re: Sort List Fields
I think SparkOut has it right, I hope Ross confirms (or not).
*Edit - I am sure this is not the most efficient way, BUT just in case that is what he's looking to do, here is one way I came up with that seems to work.
*Note - the code above is extremely verbose and can be condensed considerably. I'm sure anyone whose been working with this language for any amount of time knows this, but newer people may not.
*Edit - I am sure this is not the most efficient way, BUT just in case that is what he's looking to do, here is one way I came up with that seems to work.
Code: Select all
on mouseUp
# all of this code is in the button that sorts field "f2"...
set itemDel to tab
// first I added a marker to the lines as they originally sit...
repeat with x=1 to the number of lines of field "f2"
add 1 to tmpLineNum
put space & tmpLineNum after line x of field "f2"
end repeat
// after the lines are marked, the sort runs...
sort lines of field f2 ascending numeric by item 2 of each
sort lines of field f2 ascending numeric by item 1 of each
// I moved the field "f1" into a variable, then cleared the field...
put field "f1" into tmpFieldOne
put "" into field "f1"
/* the markers are put in a variable, removed from field "f2", and field "f1"
lines are moved to those markers...*/
repeat with x=1 to the number of lines of tmpFieldOne
put the last character of line x of field "f2" into tmpMoveList
delete the last character of line x of field "f2"
put line x of tmpFieldOne into line tmpMoveList of field "f1"
end repeat
end mouseUp
-
- VIP Livecode Opensource Backer
- Posts: 9665
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Sort List Fields
This is what I meant, that the field as a whole is not sorted numerically, but that each line is, independently.
But I will wait for the OP....
As for sorting line by line:
LC cannot do the above natively; you have to parse individual lines and work it out.
Craig
But I will wait for the OP....
As for sorting line by line:
Code: Select all
on mouseUp
get fld "f2"
set the itemDel to tab
repeat for each line tLine in it
sort items of tLine ascending numeric
put tLine & return after accum
end repeat
put accum into fld 2
end mouseUp
Craig
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Sort List Fields
I have a handler that does this, will post when I get back to my Mac.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9838
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Sort List Fields
Do they need to be physically separate fields? Might this be one field with three tab-delimited columns?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Sort List Fields
As Reichard suggested:
See attached stack. Jim LambertMight this be one field with three tab-delimited columns?
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Sort List Fields
Here's my parallel sort handlers:
This could probably be faster if it used referenced variables or script locals, but that's the idea.
Code: Select all
on parallelSort -- parallel sort of several flds by a key field
put fld 1 into tOrigList -- the fld that determines the sort order
sort lines of fld 1
-- now add the dependent fields:
sort lines of fld 2 by arrange(each,tOrigList,2)
sort lines of fld 3 by arrange(each,tOrigList,3)
-- etc.: add any number of other fields here
end parallelSort
function arrange pContent,pOrigList,pFld
-- find out what line we are on:
get lineoffset(pContent,fld pFld)
-- use the original list to sort:
return line it of pOrigList
end arrange
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Sort List Fields
I see I have about five versions of parallel sorting. This one by genius Dick Kriesel is pretty cool. It's sorting items, but could be altered to use lines:
One (much different) parallel sort, done in HyperCard by Brett Sher 24 years ago, takes 37 lines. We've come a long way since then.
Code: Select all
split varB by comma
sort items of varA by varB[itemOffset(each,varA)]
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com