9 Replies Latest reply on Nov 27, 2008 9:29 AM by Orlando

    Displaying Counter

    DrDave

      Title

      Displaying Counter

      Post

      I have a script with a loop and I want to display a loop counter. To do this, I created a field in the database called zDisplayCounter_n. I then created a layout that contained that field. 

       

      Before I get into the loop, I set $nKounter to 0.

      Once I increment the counter within the loop, I SetField[Competitor::zDisplayCounter_n; $nKounter]

       

      The problem is that the counter does not seem to display the counter as in 1, 2, 3, etc. It only show when the loop is done.

       

      Do I have to "refresh" the layout or something?

       

      Thanks for you suggestions. 


        • 1. Re: Displaying Counter
          TSGal

          DrDave:

           

          Thank you for your post.

           

          I'm assuming Competitor is the name of the table where you are doing the looping.  The counter should change for each record, but when the loop is finished, it should display the the last $nKounter value in zDisplayCounter_n for the last record.  Each previous record should have a different value.  If not, then you probably set zDisplayCounter_n to be a global field instead of a Number field.  Change this, and the loop should then work.

           

          TSGal

          FileMaker, Inc. 

          • 2. Re: Displaying Counter
            DrDave
              

            Thank you for you feedback -- much appreciated

             

            Actually, each record does have a different value, after I run the script. AND the last counter is displayed on the layout when the loop is finished.

             

            Is is not possible for display the value of $nKounter as the loop is processing. My intention is to know how far through the process I am and that, in fact, things are processing as expected. 

            • 3. Re: Displaying Counter
              Orlando
                

              Hi DrDave

               

              While you are processing a script with a loop the layout will not refresh with every pass so you will not see the value you have set the field.

               

              First off in case you are not already doing it, to speed up your looping script put a Freeze Window step in at the beginning.

               

              Then in your loop you want to add a check on your counter that will an extra set of steps that will populate your display field and refresh the window every set number of records, in my example below every 100 loops the field will be set and the window refreshed.

               

              Something like this 

                

                #

                Set Variable [$nKounter; 0

                Loop 

                  # YOUR PROCESS

                  Set Variable [$nKounter; $nKounter + 1]

                  If [ Mod ( $nKounter ; 100 ) = 0 ]

                    Go to Layout [WithDisplayCounterOn] 

                    Set Field [Competitor::zDisplayCounter_n; $nKounter

                    Refresh Window []

                    Freeze Window 

                  End If

                  Go To Record/Request/Page [Next; Exit after last]

                End Loop

                # 

               

              You dont want to do this with every pass of the loop as it will slow the porcess down, and you can also change the number "100" to be a division of you total records in another variable.

               

              Let us know how you get on. 

              • 4. Re: Displaying Counter
                DrDave
                  

                That works GREAT. Thank you

                 

                I have one remaining problem with this code-piece, and it relates to the screen -- flashing.

                 

                In my loop I have a "save records as PDF [Restore; No dialog; "$cFullName" ; Current Record"

                 

                When this command executes and for example, my FM tool bar disappears and re-appears (flashes). In addition, if I have the script debugger and/or the  Data Viewer open, the flash on or off too.

                 

                Is there any way to control this. What I'm afraid of here is that when the end-user runs this application, things will start flashing on their screen - Yikes...the phone will start ringing off the hook.

                 

                Thank you for your help. 

                • 5. Re: Displaying Counter
                  Orlando
                    

                  Hi DrDave

                   

                  I am glad this works for you, there is not much you can do about the toolbar, debugger and Data Viewer flashing. The Debugger and Data Viewer should not affect the end user of the system but you can use the Allow Toolbars script step to hide the toolbar at the start of the script and then display it again at the end of the process.

                   

                    #  

                    Allow Toolbars [off]

                    # Scripted process

                    Allow Toolbars [On]

                    #

                   

                  That is if the toolbar is really needed by the user, otherwise you could switch it off when the database is opened.

                   

                  I hope this does the trick for you.

                  • 6. Re: Displaying Counter
                    DrDave
                      

                    Once again...you came through! 

                     

                    You have been very helpful in this forum...thank you for hanging out here! :-) 

                    • 7. Re: Displaying Counter
                      Orlando
                        

                      Always glad to help.

                       

                      How are you getting on with your system, are you on target to get the report cards done for the Friday deadline?

                      • 8. Re: Displaying Counter
                        DrDave
                          

                        Thank you for asking....

                         

                        I'm generating the Report Cards as I write this...with no screen flashing. :-)

                         

                        When done, I will put the finishing touches on the script that will email them. My next task is to figure out what limitations Gmail my put on this activity. I only have 400 Report Cards, but I doubt if Gmail will allow me to send them in one session.

                         

                        You will see that I asked another question in the forum, about getting data into FM. That's for next year...which starts in two months!

                         

                        Take care.

                        • 9. Re: Displaying Counter
                          Orlando
                            

                          Not sure on the limitations of Gmail, but using your counter and adding another If statement you could use the Pause Script step, setting a number of minutes to have a break in the process.

                           

                          And just saw your other post and replied :-)