12 Replies Latest reply on Oct 21, 2013 11:40 AM by shae1725

    Help with a Script

    shae1725

      Title

      Help with a Script

      Post

           I have 2 buttons  attached to a number field  which when pressed increase or decrease the fields value by an increment of 1  (+1 or -1)

           I will have over 20 different fields which will all have these buttons attached!

           Is it possible to create just 2 buttons with 2 scripts which could mybe set a variable to only increase/decrease the attached field?

           I am trying to avoid having so many different buttons and scripts

        • 1. Re: Help with a Script
          gcatnine

               for "+1" button the script is

               Set Field By Name[Get(ScriptParameter); Evaluate(Get(ScriptParameter) ) +1]

               for "-1" button is

               Set Field By Name[Get(ScriptParameter); Evaluate(Get(ScriptParameter) ) -1]

          the passed parameter is "Table::Field"

               if you have to control that the field does not become negative just use a variable. something like this:

               $num = Evaluate(Get(ScriptParameter)
               if $num  "your test"
                           $num = "your value"
               End if
               Set Field By Name[Get(ScriptParameter);$num]

          • 2. Re: Help with a Script
            shae1725

                 Hi Gianandrea

                 Many thanks for your help

                 I have set up the      Set Field By Name[Get(ScriptParameter); Evaluate(Get(ScriptParameter) ) +1

                 Still no sure what you mean by  the passed parameter is "Table::Field"

            Do I place +/- buttons inside the field?

            I am new to database/filemaker design so apologies if Im not understanding your instructions.

                  

            • 3. Re: Help with a Script
              gcatnine

                   when you assign a script to a button you have the possibility to assign an optional parameter

                   This parameter will be the full name of the field:  "Table::Field"

                   So the script is always the same, what change is the full name of the field passed to the script

              • 4. Re: Help with a Script
                shae1725

                     Hi

                     I now understand how this works !  But cant get it working.

                     I must have done something wrong or someother factor effecting the result

                      

                • 5. Re: Help with a Script
                  shae1725

                       Have it sorted!

                       I forgot to enclose    table::field   in ""

                       Many Thanks for your help smiley

                  • 6. Re: Help with a Script
                    shae1725

                         Hi Gianandrea

                         really hope you notice this post.

                         Trying to build the (not become negative) you recommended

                         Im a little confused as how to add this to the script

                          

                          

                         $num = Evaluate(Get(ScriptParameter)
                         if $num "your test"
                         $num = "your value"
                         End if
                         Set Field By Name[Get(ScriptParameter);$num]

                    • 7. Re: Help with a Script
                      gcatnine

                           you need it only for -1

                           Set Variable[$num; Value:Evaluate(Get(ScriptParameter))]
                           If[$num = 0]
                              Exit Script[  ]
                           End If
                           Set Field By Name[Get(ScriptParameter); $num  -1]

                      • 8. Re: Help with a Script
                        shae1725

                             Thank you thats working well

                             I also have to do the same for + because the numbers are related to sizes. I cant have an entry larger than material stock.

                             I have an understanding of how to achieve this on my own, but I noticed something in the     -Script you built

                             I didnt assign an optional parameter! How did the script know what field to subtract from?

                             I know the Script works as needed,  Im just  intrigued how the variable picks the correct field.

                             Many Thanks for your help

                              

                        • 9. Re: Help with a Script
                          gcatnine

                               Set Variable[$num; Value:Evaluate(Get(ScriptParameter))]

                               Get(ScriptParameter) gets the optional parameter passed to the script (in our case the full field name "Table::field")

                               The evaluate function gets the data stored in this field

                               So, the $num will have the value stored in "Table::field"

                               Set Field By Name[Get(ScriptParameter);$num] has as fist argument a full field name (in our case "Table::field" which was passed to the script ) and as second argument the value to be stored (in our case the number $num minus or plus 1)

                          • 10. Re: Help with a Script
                            shae1725

                                 oooh now see how the variable is set!smiley

                                  

                            • 11. Re: Help with a Script
                              philmodjunk

                                   I would suggest one small, but potentially very important modification when passing a field reference as a script paramter

                                   Instead of:

                                   "Table::Field"

                                   use:

                                   GetFieldName ( Table::Field )

                                   With the literal text in quotes, it is possible to rename either the field or the table occurrence name and the script then breaks without warning. But by using the getFieldName function, you pass the same text and now a name change will cause this calculation to update and the correct reference is still passed to the script.

                              • 12. Re: Help with a Script
                                shae1725

                                     Thanks

                                     good point!