Q1: Not quite. SelectedValuesList lists any values previously selected and ValueName is the value you just clicked. This line compares the value clicked to the list of previously selected value. This expression is True if the value was not previously selected.
Q2: correct, if the value is not selected this expression appends the value clicked to the end of the list of values already in the SelectedValuesList field. List is simply the function used to append that value. I could have used:
SelectedVauesList & ¶ & ValueName in place of List ( SelectedVauesList ; ValueName )
Q3: This is the harder to understand part of the process. You are correct that Substitute takes ¶ & Values4ScCheckBoxes::ValueName & ¶ and replaces it with a single ¶. To understand why I put a ¶ before and after the list in the field, you have to picture the pattern of values stored in that field. Say you have just two values in the field such as "AppleSauce¶Apple" and the value "Apple" is clicked to remove it from the list. Putting return characters before and after produces:
¶AppleSauce¶Apple¶. If I were to use Substitute ( SelectedVauesList ; ValueName ; "" ) and not put returns before and after, we would get: ¶Sauce, instead of AppleSauce. Including the return characters inside the subsitute function as well as adding them to the beginning and end of the list ensure that we only match and remove a complete value from the list and not a substring from another value that also happens to match.
Q4 this step trims the returns from the beginning and end of the list that were added previously. No spaces were added. As I just answered, these returns are needed in order for the substitute function to correctly remove only a previously selected value. This step is not absolutely necessary as leaving it out (try it if you want), won't produce any visible change in behavior. But if you don't, you get more and more returns added to the beginning and end of the list and if the need arises to display this field as a regular edit box format field showing all selected values, it will not display correctly due to all the appended return characters.
I think the spaces you are asking about are the spaces between the terms of ¶ & Values4ScCheckBoxes::ValueName & ¶. This does not insert spaces into the field. You are correct that I could have used ¶&Values4ScCheckBoxes::ValueName&¶ and it would evaluate the same. If you click the button for adding the & operator to an expression, you'll find that FileMaker inserts the spaces along with the ampersand for just that reason.
Hope you liked this file. Adventures #3 - Many to Many Relationships is currently in development...
I think I get nearly all of that. But with:
Set Field [ MainScCheckBoxes::SelectedValuesList; Substitute ( ¶ & MainScCheckBoxes::SelectedValuesList & ¶ ; ¶ & Values4ScCheckBoxes::ValueName & ¶ ; ¶ ) ]
I understand now why you 'bracket with paragraph marks' ¶ & Values4ScCheckBoxes::ValueName & ¶ and then replace with ¶ to drop one complete value but only one value. It's not obvious why you do this: ¶ & MainScCheckBoxes::SelectedValuesList & ¶
I'd have assumed that every value in the SelectedValueList was separated by a ¶, so why add ¶ at the beginning and end of the list?
Q4. I see the point of trimming ¶ from the line above, but why are there 2 ¶ at the start/end, not just the 1 added by
¶ & MainScCheckBoxes::SelectedValuesList & ¶ ?
Adventures 1 & 2 are phenomenal achievements.......sadly my brain/knowledge is scoring quite so highly!!!
But your brain is doing the right thing. It is prompting you to ask questions instead of just accepting my design without question. That leads you to a better understanding of how things work and enables you to create your own solutions instead of just applying the ideas of others and hoping that they will work.
Look at this example:
You have this list of selected values:
If I don't put those extra ¶ characters at beginning and end of the list, the following expressions would fail to make any change to this list:
Substitute ( SelectedValues ; ¶ & Apple & ¶ ; ¶ )
Substitute ( SelectedValues ; ¶ & Pear & ¶ ; ¶ )
As the text patterns: ¶ & Apple & ¶ and ¶ & Pear & ¶ do not exist anywhere in SelectedValues. Keep in mind that we have no way of knowing in advance where any given value might appear in that list. The list is created in the order in which the values are clicked--just like happens when you click check boxes in an actual check boxes field.
Great, I'm getting there. Last Q: Why do you have to trim 2, not 1 ¶ ? ie. won't you have only added 1 ¶ at the beginning and end?
Yep. I have one extra ¶ at the beginning of the list and one extra ¶ at the end. That makes two characters to remove from the list to "clean up" the list and that's exactly what this final scrip step does.
The penny has finally dropped !! Thanks.
The use of 'Length' was the critical bit. I'm not yet used to holding the purposes/ rules of function use in my head yet......they tend to leak out 10 seconds after reading.......:)
Keep in mind that since this is all in a working database file, you can make copies of things--even the whole file and then experiment by changing parts of the script/calculation/layout to see what happens when you make the change.