7 Replies Latest reply on Oct 28, 2009 11:08 AM by TKnTexas

    Exit on Last

    TKnTexas

      Title

      Exit on Last

      Post

      I have script that needs to go through a found set of records, evaluating and performing an action.  Currently I freeze the window at the beginning of the loop and upon completion I do a refresh.  With or without these two script steps I have a problem. 

       

      The loop evaluates the records correctly (and quickly with windows frozen).  However, it continues to run at the end of the records.  Reading the script it clearly shows the EXIT AFTER LAST.  Because I can see the "slider" on the right hand move down as records are evaluated I can judge when to hit escape.  At that point the window does a refresh.  

       

      I have broken the whole process of importing text files (2 files) into about 12 steps, that are executed manually.  I have trouble shooted it and all modules work flawlessly except for this one aspect.  Any suggestions?

        • 1. Re: Exit on Last
          philmodjunk
            

          What you describe Should work. Since it doesn't we need to figure out why it doesn't work. (I've been using Go to record (next, exit after last) since that was the only script branch available in filemaker.)

           

          Two suggestions:

          1. If you have FMP advanced, use the debugger to run this script at least for a few cycles. You'll likely spot some detail of your script or a layout based script trigger that is not doing what you thought it would do.
          2. Post the exact script here, you can copy and paste scripts from either a database design report (FMP advanced) or by printing a PDF of the script and copying it from the PDF.
          • 2. Re: Exit on Last
            TKnTexas
                

            2a) Loop

            Go to Layout [ "ImportScreen" (IMPORT_INVO) ] Replace Field Contents [ IMPORT_INVO::CheckDate; Replace with calculation: IMPORT_CR::gCkDate ]

            [ No dialog ] Adjust Window

            [ Maximize ] Freeze Window

            Go to Record/Request/Page

            [ First ] Set Variable [ $VendNum; Value:IMPORT_INVO::Test ] Loop

            If [ IMPORT_INVO::Test = "Real Data" ] Set Field [ IMPORT_INVO::VendNum; $VendNum ]

            Else

            Go to Record/Request/Page

            [ Next ] Set Variable [ $VendNum; Value:IMPORT_INVO::Test ]

            Go to Record/Request/Page

            [ Next; Exit after last ]

            End If End Loop

            Refresh Window Perform Find [ Specified Find Requests: Find Records; Criteria: IMPORT_INVO::VendNum: "=" "" ]

            [ Restore ] Delete All Records

             

            Great, I got the script to paste.   The essence of the loop to paste the appropriate Vendor Num to each record that doesn't have it. 

            • 3. Re: Exit on Last
              philmodjunk
                

              Cleaning up the pasted script for better readability:

               

              Go to Layout [ "ImportScreen" (IMPORT_INVO) ]

              Replace Field Contents [ IMPORT_INVO::CheckDate; Replace with calculation: IMPORT_CR::gCkDate ][ No dialog ]

              Adjust Window [ Maximize ]

              Freeze Window

              Go to Record/Request/Page [ First ]

              Set Variable [ $VendNum; Value:IMPORT_INVO::Test ]

              Loop

                  If [ IMPORT_INVO::Test = "Real Data" ]

                     Set Field [ IMPORT_INVO::VendNum; $VendNum ]

                 Else

                      Go to Record/Request/Page [ Next ]

                      Set Variable [ $VendNum; Value:IMPORT_INVO::Test ]

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

                 End If

              End Loop

              Refresh Window

              Perform Find [ Specified Find Requests: Find Records; Criteria: IMPORT_INVO::VendNum: "=" "" ][ Restore ]

              Delete All Records

               

              Note the portion in blue. If IMPORT_INVO::Test = "Real Data", then the script stays on that record forever because the Go to Record (next) is inside the else clause.

              • 4. Re: Exit on Last
                TKnTexas
                  

                Instead of Go to Next (exit after last)  would just be Go to Next?  Where would the exit if last step go?  After the END IF before the End Loop?

                • 5. Re: Exit on Last
                  raybaudi
                     ...not to mention that there are two Go to Record [ next ] !
                  • 6. Re: Exit on Last
                    philmodjunk
                      

                    If you want the script to move to the next record with each pass through the loop, move it after the End IF.

                     

                    Daniele (Raybaudi) has pointed out that you have two Go to record [next] steps and this is likely not what you want.

                    • 7. Re: Exit on Last
                      TKnTexas
                        

                      I took out the 1st Go to Next.  Moved the Go to Next, exit after last to just after the EndIF.  With the Windows frozen during the loop process, it is a blink to finish on my MacBook Pro where I develop. 

                       

                      I do appreciate the help from both of you.  Again, PhilModJunk you have rescued me on this project.  This has been a great exercise in learning more advanced scripting using ver10.  And providing me with a good tool. 

                       

                      More goal is to learn LOTS more (script triggers and automated back ups are next on the list). I have applications I created starting with ver3 that I want to re-do using ver10 so I can commercially market them.  Thanks again.