Page 1 of 1

Sorting a list by item [SOLVED]

Posted: Fri Apr 04, 2014 2:44 pm
by atout66
Hi to all,

I want to sort a list. I try to follow the examples of the dictionnary but I must make something wrong :mrgreen:
Here is my code:

Code: Select all

set itemDelimiter to "|" --  each line has 5 items.
   get field "lignesDeResultat" -- The first item is any word like "aWord" , "bWord" , "cWord", etc.
   sort IT ascending international by item 1 of field "lignesDeResultat"
   put IT into  fld "lignesDeResultat"
I have no syntax error but the fld "lignesDeResultat" doesn't update either !!!
Any idea around ?

Kind regards.

Re: Sorting a list by item

Posted: Fri Apr 04, 2014 3:05 pm
by atout66
I notice one mistake in the code when I wrote

Code: Select all

set itemDelimiter to "|"
instead of

Code: Select all

set the itemDelimiter to "|"
but this changes nothing...
Also, the checkboxe <Don't wrap> and <Lock text> of the field "lignesDeResultat" are unchecked.

Re: Sorting a list by item

Posted: Fri Apr 04, 2014 3:15 pm
by Thierry
atout66 wrote:Hi to all,

I want to sort a list. I try to follow the examples of the dictionnary but I must make something wrong :mrgreen:
Here is my code:

Code: Select all

set itemDelimiter to "|" --  each line has 5 items.
   get field "lignesDeResultat"
   sort IT ascending international by item 1 of field "lignesDeResultat"
  -------------------------------------------^^^^^^   of  IT  ^^^^^^^^^
   put IT into  fld "lignesDeResultat"
Does this help?

By the way, what does ascending international?
I don't see it in the dictionary..

Regards,

Thierry

Re: Sorting a list by item

Posted: Fri Apr 04, 2014 3:31 pm
by dunbarx
Hi.

I think you want:

Code: Select all

 sort IT ascending international by item 1 of each
The sort command in this construction form needs a sortKey that is referenced within the data to be sorted. You can use what you had, but the sortKey is then a single external reference, and not based on the text itself. I would be surprised if it sorted at all, though it would likely not throw an error.

Craig

Re: Sorting a list by item

Posted: Fri Apr 04, 2014 3:45 pm
by atout66
By the way, what does ascending international?
I don't see it in the dictionary..
Euh... I found it somewhere, in a lesson surely, don't remember.
It allows to sort letters with accent like "é" , "à" , etc., in french or other languages with that kind of letters.
So you get word starting with an "e" and if you don't 'ask' the "international", the next word will be starting with an "f" (if so), skipping a word like "éléphant" which would be placed at the end of the list.
I'm not sure to be so clear at all, but I really don't remember where i saw that. :shock:

Re: Sorting a list by item

Posted: Fri Apr 04, 2014 3:47 pm
by Klaus
Bonjour atout66,

as Craig wrote! :D

General hint: Do not use IT more than once or at all if not neccessary, use a variable insead!
IT will change when you least exspect IT 8)
...
set itemDelimiter to "|" -- each line has 5 items.
put field "lignesDeResultat" into tText
sort lines of tText ascending international by item 1 of each
put tText into fld "lignesDeResultat"
...

Best

Klaus

Re: Sorting a list by item

Posted: Fri Apr 04, 2014 3:49 pm
by atout66
Craig, I'm glad to tell you that you can be surprised by yourself with no limit :lol:
Your script works perfectly !

Thanks to all of you.

Re: Sorting a list by item

Posted: Fri Apr 04, 2014 4:01 pm
by Thierry
atout66 wrote:
By the way, what does ascending international?
I don't see it in the dictionary..
Euh... I found it somewhere, in a lesson surely, don't remember.
It allows to sort letters with accent like "é" , "à" , etc.,
Merci and sorry for the wrong input above :)

Thierry