2 Replies Latest reply on Jan 13, 2014 8:20 AM by philmodjunk

    Checkbox values ?

    B_1

      Title

      Checkbox values ?

      Post

           If I am using a checkbox, what is the value I use for it when writing a script/calculation?

            

           For example if I was writing a code, and I want the code to say that Checkbox01 is checked, would the value be Yes, 1, etc?

           The old system I used the value was 1 for checked and 0 for unchecked. Is this the same case?

        • 1. Re: Checkbox values ?
          philmcgeehan

               It depends on what values you've selected.

               I sometimes use a Value List called YesChecked, and it only has one value in it: Yes.

               So in my code I can refer to it like this:

               if [table::field = "Yes"] .... 

          • 2. Re: Checkbox values ?
            philmodjunk

                 Check boxes are simply formats for entering specific values into a field. If your value list specifies values of 1 or 0 for a check box formatted field, then you can test for values of 1 or 0 in the field and you can change the value of the field using set field just as you would any field that does not have a check box field formatted.

                 Example:

                 If you have a value list with values 1, 0, then

                 Set Field [ YourTable::Yourcheckboxfield ; 1 ]

                 will clear the check box for 0 and select the check box for 1.

                 But check boxes have a special ability, they allow you to build lists of values in the field separated by returns. If you have one check box for 0 and one for the value 1, then clicking both check boxes will enter both a 1 and a 0 with a return character separating them. The first value listed will be the first check box selected.

                 Thus, checking to see if a particular value is selected often requires using the filtervalues function:

                 If [ Not IsEmpty ( FilterValues ( YourTable::YourCheckboxField ; 1 ) ) ]

                 will detect if a 1 is entered into the field regardless of whether the check box for 0 is or is not selected.

                 And if you specify other values than 1 or 0 for your value list such as the following text: apple; orange ; kiwi, then clicking a check box would enter the associated text for one of those values into your field and you might use "kiwi" instead of the number 1 in the above examples.

                 If you want to use a script to select a check box without clearing other check box values you might use this script step:

                 Set Field [ YourTable::YourCheckboxFIeld ;
                                  If ( IsEmpty ( Filtervalues ( YourTable::CheckBoxField ; "kiwi" ) ) ;
                                       List ( YourTable::YourCheckboxField ; "kiwi" ) ; YourTable::yourCheckBoxField ) ]

                 (This will appear as a single line in the script editor. I've added some returns to make things easier to read.)

                 You may find that your understanding of how this works improves if you make a copy of your check box formatted field, place it next to the original copy and remove the check box formatting by returning it to "edit box" format. You can then click check boxes in the first field and then see the actual data being entered in the second.

                 IsEmpty, FilterValues, List and Set Field are all names that you can look up in FileMaker help if they are unfamiliar to you.