Having drawn my attention to the Length function while responding to another question, I've arrived at a solution using Substitute, Length and If. Definitely a straightforward blunt force attack, so a more elegant solution achieving the same result would be welcomed.
Checklist: a Text field controlled by checkboxes and a four item Value List: Alpha, Beta, Gamma and Delta.
CL Extract: A Calculation field displaying the initial letter of each Value List item in Checklist whose box has been checked. The letters are displayed in a single line, in the order the checkboxes are listed (controlled by the formula), and separated by a trailing space.
If ( Length ( Checklist ) > Length ( Substitute ( Checklist ; "Alpha" ; "" ) ) ; "A " ; "" ) &
If ( Length ( Checklist ) > Length ( Substitute ( Checklist ; "Beta"; "" ) ) ; "B " ; "" ) &
If ( Length ( Checklist ) > Length ( Substitute ( Checklist ; "Gamma" ; "" ) ) ; "G " ; "" ) &
If ( Length ( Checklist ) > Length ( Substitute ( Checklist ; "Delta" ; "" ) ) ; "D " ; "" )
I have inserted returns in the formula to place each block on a separate line, and clarify its repeating structure.
As mentioned, a more elegant solution providing the same results would be welcomed. Until then I hope someone else may also find this useful.
Substitute ( Checklist ; ["Alpha" ; "A "] ; ["Beta" ; "B "] ; ["Gamma" ; "G "] ; ["Delta" ; "D "] ; [¶ ; " " ] )
Thanks for this, Phil,
Very similar to my initial solution, but it did send me back to the Specify Calculation window for a double Doh! experience, once seeing the ¶ button I'd been blind to previously, the other on noticing that step of wrapping a second Substitute statement around the whole thing was obviously an unnecessary extra step.
The one thing Substitute doesn't do is put the single letters in the same order as the checkbox list. FMP places items in a checkbox controlled field in the order that the boxes have been checked, rather than the order they are listed, and Substitute won't change that order when condensing the list.
Good, clean solution, and one that led to some learning. For now, though, I'll stick with the If, Length, Substitute one above. Although it's not as clean, it does put the letters in list order, easing recognition by the reader when they're placed in a printed list.
There are easier ways to do this from the start--such as setting up a "use values from field" value list for these values and specifying the first letter as field 1 and the full text as field two. (But this might create issues for you in getting the desired order for your values in the value list.)
And here's an auto-enter calculation that takes the values as entered by the mouse clicks and re-orders them to fit the order of the selected values as listed in the value list:
FilterValues ( ValueListItems ( Get ( FileName ) ; "YourValueListNameInQuotesHere" ) ; self )
Be sure to clear the "do not replace existing values..." check box.
Note that with this change, you can modify the values used in the value list and not have to redefine your calculations.