6 Replies Latest reply on Mar 29, 2015 11:49 AM by JacquiProut

    If script help

    JacquiProut

      Title

      If script help

      Post

      Can anyone help me with a script.I am new to filemaker and want to create the following action

      The two fields I will be working with are called

      Time

      Meal

      The script I want to perform is as follows

      If TIME is between 06.:00 and 12:00 populate the MEAL field with Breakfast

      If TIME is between 12:01 and 14:00 populate the MEAL field with Lunch

      If TIME is between 14:01 and 22:00 populate the MEAL field with Dinner

      If TIME is between 22:01 and 05:59  populate the MEAL field with Bedtime

      END Script

      Any suggestions (in plain english)  for this and recommendations for good books on scripting gratefully received

       

       

        • 1. Re: If script help
          philmodjunk

          There are multiple ways to set this up. Assuming that Time is a field of type Time, you might use a case function like this:

          06.:00 and 12:00
          12:01 and 14:00 
          14:01 and 22:00
          22:01 and 05:59

          Case ( Time < GetAsTime ( "6:00" ) ; "Bedtime" ;
                     Time < GetAsTime ( "12:01" ) ; "Breakfast" ;
                     Time < GetAsTime ( "14:01" ) ; "Lunch";
                     Time < GetAsTime ("22:01" ) ; "Dinner";
                     "Bed time"
                   )

          The above calculation works with out checking both lower and upper limits because case functions evaluate from top to bottom and go with the first expression that's True.

          Note that it's also possible to also set up a table of text and time values and "look up" such a result as well. The "look up" method allows users to modify the parameters of what text is returned for what time values without having to ask you as the developer to redefine the calculation.
           

          • 2. Re: If script help
            JacquiProut

            Thanks again.

            I get the message that you can see in the attached clip about an Operator is required here and it highlights time which is my field name

            Thanks as ever

            Jacqui

             

            • 3. Re: If script help
              TSGal

              Jacqui Prout:

              At the end of the first line of the calculation, you are missing a semi-colon after "Bedtime".

              TSGal
              FileMaker, Inc.

              • 4. Re: If script help
                JacquiProut

                Hi All

                I have created the suggested script it read as follows

                If

                Case ( for filemaker set up excel Converted::Time < GetAsTime ( "06:00:00" ) ; "Bedtime" ;
                           for filemaker set up excel Converted::Time < GetAsTime ( "12:01:00" ) ; "Breakfast" ;
                           for filemaker set up excel Converted::Time < GetAsTime ( "14:01:00" ) ; "Lunch";
                           for filemaker set up excel Converted::Time < GetAsTime ("22:01:00" ) ; "Dinner";
                           "Bed time"
                         )

                End if

                 

                I have set a button on a field call Meal to perform this script but nothing happens.

                All help gratefully received 

                Jacqui

                Jacqui

                • 5. Re: If script help
                  philmodjunk

                  This is not a script, but a calculation. It can't just be "performed" by a button click as it would have to be set up as part of a script step/button option that uses the calculation. You'll need to either set this up as the calculation for a calculation field or a text field with an auto-enter calculation or fix whatever error was made setting this up with your button.

                  If you want to fix the button setup, please share the exact details of how you set this up.

                  • 6. Re: If script help
                    JacquiProut

                    perfect -  all I had to do was change the field to a Calculation field and paste the formula back into it.

                    It works a treat, my diabetes nurse will be very impressed as I can now record my levels and my food in one place and import my data from my glucose monitor

                    Many thanks

                    Jacqui