7 Replies Latest reply on Dec 29, 2014 5:28 AM by philmodjunk

    Adventure 2 EVS: Scrolling Checkboxes: Select DeSelect Check box value

    tays01s

      Title

      Adventure 2 EVS: Scrolling Checkboxes: Select DeSelect Check box value

      Post

      I'm just trying to understand the script and apologies that my Qs [[? ]] are at a rather basic level !

      #If value is not selected, add it to the list. If value has already been selected, remove it from the list.

      #

      If [ IsEmpty ( FilterValues ( MainScCheckBoxes::SelectedValuesList ; Values4ScCheckBoxes::ValueName ) ) // Clicked value is not in list ]

      [Q: So effectively MainScCheckBoxes::SelectedValuesList is the list of potential values and Values4ScCheckBoxes::ValueName are the values to filter.]]

      #append clicked value to list

      Set Field [ MainScCheckBoxes::SelectedValuesList; List ( MainScCheckBoxes::SelectedValuesList ; Values4ScCheckBoxes:: ValueName ) ]

      [[Q: If the value wasn't listed in the filter, it's appended to the list. Is 'List' saying list everything in MainScCheckBoxes::SelectedValuesList and whatever is 'checked' in Values4ScCheckBoxes:: ValueName? Since the latter field should contain all checked values, why does it need also the first field?]]

      Else

      #delete clicked value from list

      Set Field [ MainScCheckBoxes::SelectedValuesList; Substitute ( ¶ & MainScCheckBoxes::SelectedValuesList & ¶ ; ¶ & Values4ScCheckBoxes::ValueName & ¶ ; ¶ ) ]

      [[Q: Does "¶ & MainScCheckBoxes::SelectedValuesList & ¶ " simply mean an item in the MainScCheckBoxes::SelectedValuesList list that equals the value of the item deleted in "¶ & Values4ScCheckBoxes::ValueName & ¶" and replaced by ¶?

      Why is a "¶" put either side? Is it necessary to specify an item rather than a field]]

      Set Field [ MainScCheckBoxes::SelectedValuesList; Middle ( MainScCheckBoxes::SelectedValuesList ; 2 ; Length ( MainScCheckBoxes::SelectedValuesList ) - 2 ) // this step trims off the extra ¶'s at beginning and end of the list ]

      [[Q: Trimming 2 characters from beginning/end is when using "¶[space]"/ "[space]¶"? I assume the space is only there for easier readability?]]

       

        • 1. Re: Adventure 2 EVS: Scrolling Checkboxes: Select DeSelect Check box value
          philmodjunk

          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...

          • 2. Re: Adventure 2 EVS: Scrolling Checkboxes: Select DeSelect Check box value
            tays01s

            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!!!

            • 3. Re: Adventure 2 EVS: Scrolling Checkboxes: Select DeSelect Check box value
              philmodjunk

              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:

              Apple¶
              Orange¶
              Pear

              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.

              • 4. Re: Adventure 2 EVS: Scrolling Checkboxes: Select DeSelect Check box value
                tays01s

                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?

                • 5. Re: Adventure 2 EVS: Scrolling Checkboxes: Select DeSelect Check box value
                  philmodjunk

                  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.

                  • 6. Re: Adventure 2 EVS: Scrolling Checkboxes: Select DeSelect Check box value
                    tays01s

                    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.......:)

                    • 7. Re: Adventure 2 EVS: Scrolling Checkboxes: Select DeSelect Check box value
                      philmodjunk

                      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.