1 2 Previous Next 16 Replies Latest reply on Apr 10, 2014 12:52 AM by rexb

    simple counter

    rexb

      I need to count and display the number of times a particular button is pressed (running total). It sounds simple, but I can not get anything to work. (FMP12) How would you go about it?

        • 1. Re: simple counter
          taylorsharpe

          I assume when you click the button, you have a script assigned.  You can have the script add record the value.  I would probably have a table that stores the timestamp and maybe account name everytime the button is pressed (you would have to go to the other layout, create new record and store the tiemstamp and account name and return to the original layout). That way you know who and when a the button was pressed.  Or if you just need to know the number of times pressed in a session, I would probabyl use a global variable. 

          1 of 1 people found this helpful
          • 2. Re: simple counter
            rexb

            Thanks for the prompt reply... I just only need a number count that can be manually reset one time each month. I would add the same script to each of twelve buttons to give one total into a single counter field. (number field?) Seems easy, but I can't get my head around a way of achieving it!

            • 3. Re: simple counter
              taylorsharpe

              Use the same script and just create a new record and add a 1 in field that you can total up. 

               

              Go To Layout ( Counter )

              Enter Browse Mode

              New Record Request

              Set Field ( Count ; Value: 1 )

              Go To Layout ( Original )

              • 4. Re: simple counter
                rexb

                Tried all that but it won't work for me (as yet!)

                Any further suggestions?

                • 5. Re: simple counter
                  taylorsharpe

                  Did you sum up the counts?  Or I'm not sure what you say is not working.  The above script works for counting when a button is clicked.  Did you create the script?  Can you share it here?

                  • 6. Re: simple counter
                    erolst

                    If you want to reset the value each month, you can have it done automatically by adding an additional date field.

                     

                    Simply create a Counter table with a counter field and a date field, and create one new record. Attach the following script to your buttons:

                     

                    Go to Layout [ Counter ]

                    Set Field [ Counter::counter ; Case ( Month ( Counter::countDate ) = Month ( Get ( CurrentDate ) ; Counter::counter ) + 1 ]

                    Set Field [ Counter::countDate ; Get ( CurrentDate ) ]

                    Go to Layout [ original ]

                     

                    or relate the Counter table to your other table in a Cartesian relationship (x), so you don't need to leave the layout.

                     

                    And please be more descriptive than "it won't work".

                    • 7. Re: simple counter
                      billbarman

                      you need a field to hold the count and either one or two scripts, depending on whether (case 1) you are just counting clicks or (case 2) counting clicks and performing something else when the button is clicked.

                       

                      in both cases you need a script that does this:  set field counter01 equal to  " 1 + table:counter01 "

                       

                      in the second case you need another script that runs the first script and then anything else you need to do.

                       

                      in the first case set the button to perform script 1

                       

                      in the second case set the button to perform script 2

                       

                      Hope this helps.

                      • 8. Re: simple counter
                        keywords

                        If you use the table suggested by taylorsharpe and add a further field to record which of your twelve buttons has recorded each click you will build statistics over time, and will easily be able to extract monthly counts or any other subtotal you want. If the data is retained you have data which will enable some analysis—were there more clicks this month than last month? which button gets used the most? which user clicks the most buttons? which button does that user click most?

                         

                        If you simply use a field to record the total clicks and restart it each month you (a) gather less data and (b) lose all the data at each reset.

                        • 9. Re: simple counter
                          martinc

                          I've been thinking of doing something similar- I'd like to see which buttons/scripts are not getting used.  Those with low usage should be cleared off layouts to reduce clutter.

                          Has anyone come up with a more global button click counter that could record stuff like:

                          button Name, layout, user, date

                          • 10. Re: simple counter
                            keywords

                            You could easily capture all those values in a single text calculation which gets posted into a buttonData field on the usage table.

                            • 11. Re: simple counter
                              martinc

                              If I create a sub script to create the log, how can I pass the main script name to the sub script?  Being lazy, I'd just like to add a sub-script to any Scripted button that I want to log.

                              • 12. Re: simple counter
                                erolst

                                martinc wrote:

                                 

                                If I create a sub script to create the log, how can I pass the main script name to the sub script?

                                 

                                Use a script parameter.

                                • 13. Re: simple counter
                                  BobGossom

                                  Hi,

                                   

                                  There are a lot of good suggestions on the thread, but I suspect you are getting hung up on the issue of where to actually store the data. There are a couple of methods, but the bottom line is that you'll need a separate table to hold the counts.

                                   

                                  The way I'd do it is create a table with a field for the button "name" and a field for the count. I'd then create a global field that has a "creation" relationship to the button Name field.

                                   

                                  Then every time some clicks a button, your script would set the global field to the button name and set the button count field (across the creation relationship) to itself plus 1. The first time a button is clicked, it will automatically create a record with the button name and a 1 (0 + 1) in the count field. The next time the button is clicked the button record will already be there, so it will simply increase the count field by 1. Remember to commit the record after you set the count field.

                                   

                                  Managing the monthly counts could be done in several ways, but this is a simple methodology to get started.

                                   

                                  Bob Gossom

                                  • 14. Re: simple counter
                                    martinc

                                    having trouble with a simle step- catching the name of a button in a Var  $Button

                                    I've named the button in the inspector/Position: Name.  In the script attached to the button I put Set Variable $Button, Value:Get(ActiveObjectName)].  The var $Button is not getting set. 

                                     

                                    Jumping to a separate table and setting other items such as Script Name, layout name, user, and dates is easy.

                                    1 2 Previous Next