Sort by first column, then by date in 3rd column

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

Post Reply
joyce1440
Posts: 3
Joined: Sun Jun 14, 2015 1:08 am

Sort by first column, then by date in 3rd column

Post by joyce1440 » Tue Apr 17, 2018 4:01 am

I have a large field with many columns.
The first column is Patient Number
2nd column is Patient Ledger Number
3rd Column is Date of Service

I need to sort by patient number, then by the date of service.
When I do a regular sort, it does not sort the dates correctly.
Any suggestions?

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

Re: Sort by first column, then by date in 3rd column

Post by bogs » Tue Apr 17, 2018 4:12 am

I am guessing (without seeing your code) that when you say 'regular sort', you mean that your not specifying what your sorting, but more using sort as a shotgun. By default, I believe sort treats everything as text.

If you need to sort numbers, then you would write it something like

Code: Select all

sort field "xyz" numeric ascending 
// if you want it highest to lowest, it would be 'descending'...
Pretty sure 'sort' in the dictionary goes into it pretty well. You can also use different metrics to sort, for instance

Code: Select all

sort the lines of field 1 by word 3 of each
You can make it as involved or simple as you need it.

*Edit - I checked, and this is what the dictionary says about sort type.
sortType enum

If you don't specify a sortType, the sortType is text.
Sort types -
  • international -sorts by collation according to the system locale
  • numeric -sorts by number. (Use this form if the sortKey consists of
  • datetime -treats the sortKey as a date and/or time
  • text -sorts using a codepoint by codepoint comparison
  • binary -sorts using a byte by byte comparison
Image

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

Re: Sort by first column, then by date in 3rd column

Post by dunbarx » Tue Apr 17, 2018 7:41 pm

Hi.

Know also that you can combine a sort using "&":

Code: Select all

on mouseUp
   sort fld 1  by word 2 of each & word 1 of each 
end mouseUp
And as Bogs mentioned, be sure that you include the correct sortKey, like "numeric" or "Datetime", or LC will not do what you want it to. Practice a bit on a field with a list of random text..

And know also that you cannot mix sortKey "styles" in the compact form above. In that case, where you want to sort by more than one style, you need to sort on separate lines. The good news is that LC provides stable sorts, so that each time you do sort, the previous order is maintained to the extent it can be, based on the latest sort.

That's a lot of sort



Craig Newman

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

Re: Sort by first column, then by date in 3rd column

Post by bogs » Tue Apr 17, 2018 8:31 pm

dunbarx wrote:
Tue Apr 17, 2018 7:41 pm
That's a lot of sort
It all sounds very sorted to me, but it is the sort of thing we depend on around here eh :D
Image

joyce1440
Posts: 3
Joined: Sun Jun 14, 2015 1:08 am

Re: Sort by first column, then by date in 3rd column

Post by joyce1440 » Thu Apr 19, 2018 4:56 am

Thanks-you!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”