I am building a stack of cards sorted according to an index number with the form "YY-XXXX", where YY is the last two digits of the year, e.g., "98" for the year 1998 (the year of entry), and XXXX is the order of entry in the given year, e.g., "0001","0002", etc. This number is the first word of the card name and is also contained in a field on each card named "pcfnum". Users will create a new cards having any number between 47-XXXX (1947) and 16-XXXX (2016).
My script must put the new card in the correct position in the stack, e.g., a new user-created card with "98-0538" as the first word of its name (and the sole string in the fld "pcfnum") must be placed automatically between pre-existing cards "98-0222" and "98-1005". Bear in mind that in the stack there are other pre-existing cards for years both before and after 1998, including cards created in year 2000 and thereafter having as card names "00-XXXX", "01-XXXX", etc.
Being a beginner at this, the only method that has occurred to me is have the script (1) put the new card as the last card of the subset of the stack representing the cards of the given year, (2) mark all the cards of that subset by finding "YY-" in the fld "pcfnum", and (3) sort the marked cards by the fld "pcfnum". My hope was that just the marked cards would be sorted, leaving the position of all the unmarked cards unchanged, but the script not only correctly sorted the marked cards, but sorted the entire stack with the first cards being the "00-XXXX" and the last cards being "99-XXXX".
I couldn't find in this forum this kind of questions. Hoping there is a solution towards which I could be pointed, I pose the problem.
Monty
Sorting a subset of stack of cards w/o sorting stack
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Sorting a subset of stack of cards w/o sorting stack
This should work. I tried it with lines in a field and it works. The same idea should work with cards also.
To sort them numerically from 1947 to 2016 correctly, you have to rekey them to starting with 0 (for year 1947). You do that by adding 53 to every number (47+53=100) and only using the last 2 digits for the sort.
e.g.
(1947) 47 + 53 = 100 , use 00
(1993) 93 + 53 = 146 , use 46
(2000) 00 + 53 = 53 , use 53
(2016) 16 + 53 = 69, use 69
You can see that the new numbers will sort correctly. Notice that the original field is unchanged, the calculations are only used in the sort.
The following will work for lines in a field with the dates being as you described.
I will leave it to you to use the same principle but with cards. It may not be fast but it will work.
If you have too many cards and it is too slow (or does not finish), you may have to put the dates and the card number in a variable, sort that, then use it to rearrange the cards.
To sort them numerically from 1947 to 2016 correctly, you have to rekey them to starting with 0 (for year 1947). You do that by adding 53 to every number (47+53=100) and only using the last 2 digits for the sort.
e.g.
(1947) 47 + 53 = 100 , use 00
(1993) 93 + 53 = 146 , use 46
(2000) 00 + 53 = 53 , use 53
(2016) 16 + 53 = 69, use 69
You can see that the new numbers will sort correctly. Notice that the original field is unchanged, the calculations are only used in the sort.
The following will work for lines in a field with the dates being as you described.
Code: Select all
set itemDelimiter to "-"
sort lines of field "x" numeric by char -2 to -1 of ((item 1 of each) + 53)
If you have too many cards and it is too slow (or does not finish), you may have to put the dates and the card number in a variable, sort that, then use it to rearrange the cards.
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/