Sort cards

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Tomalain
Posts: 8
Joined: Wed Nov 01, 2017 3:49 pm

Re: Sort cards

Post by Tomalain » Thu Nov 02, 2017 10:34 pm

Hi Jean-Marc

OK Done with this handler:

on mouseUp
Answer "Séquence de tri des cartes bibliothèque:" with "Année" or "Auteur" or "Numéro"
If it = "Année" then
put "Tri "&it
sort cards by field "Année" of group "BG-Livre"
else
if it = "Auteur" then
put "Tri "&it
sort cards by field "Auteur" of group "BG-Livre"
else
put "Tri "&it
sort cards by field "No" of group "BG-Livre"
end if
end if
beep
ask "Fin du Tri "&it
end mouseUp

Now it operates, result is not completely correct, but due to unexpected spaces in fields

Thanks to all of you for the advices,
Alain

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9582
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Sort cards

Post by dunbarx » Thu Nov 02, 2017 11:40 pm

Good.

You can tighten up excess spaces in several ways. One good one is something like this:
repeat for each word tWord in it
put tWord & space after temp
end repeat
But know that this will only really work with single lines, which is what I assume your fields contain. If you read the handler, you will see that returns, for example, are deleted. Does this help? If not, can you propose a way to simply lose extra spaces but keep all other control characters intact?

C'mon, Jacque, just a little?

Craig

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Sort cards

Post by bogs » Fri Nov 03, 2017 3:40 am

dunbarx wrote:
Thu Nov 02, 2017 11:40 pm
C'mon, Jacque, just a little?
You know, I heard she has a little something tucked away in her secret files... :twisted:
Image

Tomalain
Posts: 8
Joined: Wed Nov 01, 2017 3:49 pm

Re: Sort cards

Post by Tomalain » Fri Nov 03, 2017 9:57 am

Hi,
thanks to Craig and Jean-Marc,
My Sort now operates, but I remain suspicious: the SORT command seams to be not predictable, and not stable over the releases of LC.

Concerning spaces, thanks for the suggestion, I will reinforce checking at data entry

Alain

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9582
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Sort cards

Post by dunbarx » Fri Nov 03, 2017 2:39 pm

@Tomalain

I bet that there still are small glitches in the stack, not in the command.

@ Bogs.

Jacque believes that we should never task new users with what I used to call homework. I was asking if just this one time I could.

Craig

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Sort cards

Post by bogs » Fri Nov 03, 2017 5:02 pm

:oops: putting on my dunce cap, and moving to the corner :oops:
Image

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Sort cards

Post by MaxV » Fri Nov 03, 2017 6:00 pm

Tomalain wrote:
Fri Nov 03, 2017 9:57 am
Hi,
thanks to Craig and Jean-Marc,
My Sort now operates, but I remain suspicious: the SORT command seams to be not predictable, and not stable over the releases of LC.

Concerning spaces, thanks for the suggestion, I will reinforce checking at data entry

Alain
Did you specify the sortType?
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9582
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Sort cards

Post by dunbarx » Fri Nov 03, 2017 7:39 pm

@ Max. I had mentioned the sortType in an earlier post, when speaking about the field "annee".

@ Tomalain. But Max's point bears examination.

Craig

Tomalain
Posts: 8
Joined: Wed Nov 01, 2017 3:49 pm

Re: Sort cards

Post by Tomalain » Fri Nov 03, 2017 7:46 pm

Hi,
As sort type I used "Numeric" for field supposed to contain number ("No"), and later suppressed this parameter.
I will re-introduce when I will be sure all spaces cleared

probably yes, a small glitch in the stack, no idea what it could be
thanks
Alain

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9582
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Sort cards

Post by dunbarx » Fri Nov 03, 2017 8:15 pm

Alain, note that there is a native "dateTime" sortKey for your field "annee".

We must all be careful when sorting dates, numbers and text, and VERY careful when sorting combinations of those data types.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Sort cards

Post by jacque » Fri Nov 03, 2017 9:29 pm

dunbarx wrote:
Fri Nov 03, 2017 2:39 pm
Jacque believes that we should never task new users with what I used to call homework. I was asking if just this one time I could.
Just this once then. I will grit my teeth and move on. :P

Since plain "sort" only looks at the beginning of the text, it might be faster to loop through the lines. This will trim leading and trailing spaces:

Code: Select all

function stripSpaces pList
  repeat for each line L in pList
    put word 1 to -1 of L & cr after tList
  end repeat
  return tList
end stripSpaces
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”