11 Replies Latest reply on Nov 16, 2009 12:25 PM by j.wegner

    Loop exiting early

    j.wegner

      Title

      Loop exiting early

      Post

      Hi all,

       

      I have a loop set up, that is performing another script.  The loop is set to exit when a variable reaches a certain value.  The variable is increased by 1 inside of the script that is performed by the loop.  My problem is that the loop is exiting early.   Here is a copy of the necessary code :

       

      Main Script(Loop Portion)

       

      Loop

             Exit Loop If[$$NewDate >= NewEndDate

             Perform Script["AddNewVacationInfo QCG"]

      End Loop

      do some stuff

       

      AddNewVacation QCG(just the important stuff)

       

      Set Variable[$a; Value: 1]

      Loop

            If[$a = $Day]

                   do some stuff

                   Set Variable[$$NewDate; Value: $$NewDate + 1]

                   Exit Script []

            End If

            Set Variable[$a; Value: $a + 1]

      End Loop

       

      _____________________________________________________________________________________

       

      To be more specific, the loop is ending when $$NewDate is 4 and $$NewEndDate is 31.  I know that these are the values, as I am watching them via the script debugger. Clearly, 4 is not greater than or equal to 31..  so my loop shouldn't be exiting.    Any ideas?

       

       

       Thanks,

      J Wegner

        • 1. Re: Loop exiting early
          mrvodka
             Could you post both of the full sripts?
          • 2. Re: Loop exiting early
            philmodjunk
              

            Check each instance of the variable $$NewEndDate in your script. If one of these is misspelled then you might have a situation where you think you typed in $$NewEndDate and really typed something else. That might cause the following expression:

             

            $$NewDate >= $$NewEndDate

             

            to evaluate as 4 >= /*no value */

             

            which would cause your loop to exit.

             

            In your post, you posted the exit Loop step as "Exit Loop If[$$NewDate >= NewEndDate" If that's how it looks in your script then NewEndDate is not the same thing as $$NewEndDate and that might explain things.

            • 3. Re: Loop exiting early
              j.wegner
                

              I would, but each script is 50+ steps..  As far as I know there is no way to copy a script to a text format?  If there is let me know.

               

              Is there something that you would be looking for that I can look for? 

               

               

               

              • 4. Re: Loop exiting early
                mrvodka
                   I caught that too, but I think it was a typo. Otherwise, one would get an error as it wouldnt represent a field or variable.
                • 5. Re: Loop exiting early
                  mrvodka
                     Print to PDF and then copy paste.
                  • 6. Re: Loop exiting early
                    philmodjunk
                      

                    Since you have FMP advanced, you can generate a database design report and copy the script from there.

                     

                    Mr. Vodka, I agree on the "typo in original post", but it does suggest one explanation which is a mistyped (but still correct format) variable name.

                     

                    $NewEndDate or $$NewEndDat

                     

                    Would be two possible examples.

                     

                     

                    • 7. Re: Loop exiting early
                      j.wegner
                        

                      Ok, here is the paste of the code.  I put them at pastebin to avoid the really long post.

                       

                      AddNewVacation QCG(Contains the main loop) ---   http://pastebin.com/m202ea82f

                       

                      AddFromVacInfo QCG --- http://pastebin.com/m6d83f1bb

                       

                      Thanks for all your help!!!

                       

                      EDIT:  Sorry for the poor formatting on pastebin.  It handles most characters, but apparently not greater than/equal to..  Everywhere that is says &#8805  should be >=

                      • 8. Re: Loop exiting early
                        philmodjunk
                          

                        Some indenting would have made the code easier to read also. :smileywink:

                         

                        A visual scan of your code didn't show anything obvious.

                         

                        Your code suggests that you may have a less than optimum database design. If you were to modify your table structure to use a related table of days instead of dedicated fields within the same record, you could probably create a much simpler script and this simpler script would be easier to debug, analyze and maintain.

                        • 9. Re: Loop exiting early
                          j.wegner
                            

                          Sorry for the lack of indenting.  Just copy and pasted it from the database design report.  I'll put some indentation in there in a minute.

                           

                          Here's a picture of really what's confusing me.

                           

                          http://img694.imageshack.us/i/fmpdebug.png/

                           

                          My debugger is showing me that $$NewDate = 4,  $$NewEndDate = 31, and $$NewDate >= $$NewEndDate is True.

                           

                          This same set of variables holds true before the exit loop step, during the exit loop step, and after the exit loop step.

                           

                          I just can not find any logical reasoning for why I would be getting this error.

                          • 10. Re: Loop exiting early
                            philmodjunk
                              

                            I think I've got it. Is it possible that the field you are using to assign a value to $$NewEndDate is a text field?

                             

                            Using a text based comparison, "4" >= "31" is true.

                             

                            Try enclosing the field in a getasNumber function:

                             

                            GetAsNumber( Office Files QCG::NewVac EndDate )

                            • 11. Re: Loop exiting early
                              j.wegner
                                

                              I'm home from work at this point, and won't be able to access the database to verify if that field is text or number.  It should be number, but I may have accidentaly (stupidly) made it as text.  That seems to be the best solution that I can develop, being that the only other solution I have is FileMaker is broken :P

                               

                              Just a quick question..  Does FileMaker use ascii values to compare textual values to numerical values?  Doesn't change the correctness of this solution; I'd just like to know for further reference. 

                               

                              UPDATE : It worked!  Silly me, I was moving too quick and made that field a text, instead of a number!  Script runs fine.  Thanks everyone so much for your help!