7 Replies Latest reply on Mar 5, 2009 5:38 PM by nealt

    Find in a script problems continue

    nealt

      Title

      Find in a script problems continue

      Post

      I am still having problems in a scripted find in a loop so I will ask my question in a different way.


      This works but of course I do not want to manually put in n:
      P  is a field on the form which is in tableView

      Enter Find Mode
      Show custom Dialog(Input #1:firstprint,Input#2:lastprint
      Set field (p;firstprint)
      Set Variable($f;Value:firstprint)
      loop
          exit loop if (p>lastprint)
          Show custom dialog(Input#1:p)
          perform find[]
          Set variable [$f:Value $f+1]
          Set Field[p;$f]
      End loop

      But this does not work:

      Enter Find Mode
      Show custom Dialog(Input #1:firstprint,Input#2:lastprint
      Set field (p;firstprint)
      Set Variable($f;Value:firstprint)
      loop
          exit loop if (p>lastprint)
          perform find[]
          Set variable [$f:Value $f+1]
          Set Field[p;$f]
      End loop


      Basically if I manually enter a number for P the find works properly. If I enter P from a calculation the find does not increment but remains at the previous p value.

      Thanks.

















        • 1. Re: Find in a script problems continue
          deltatango
            

          this is too vague.

           

          what is the purpose of this script?

           

          try to give more data about it. 

          • 2. Re: Find in a script problems continue
            nealt
              

            I have simplified the code here.

            I have a Tableview layout with a numeric field p.I use table view because it displays the related data very nicely. P is located in the header of the layout. I can nicely manually change p to find tableviews for a given value of p. However if I use the find in a  loop which increments p over a range of values p is not being used in the set field step before the perform find command. 

             

            When I get this to work I will place a print command after the perform find. So this will print out tableviews with different values of p.

            • 3. Re: Find in a script problems continue
              deltatango
                

              The reason why is because enter find mode is not in your loop.

               

              so your script does this:

               

              enter find mode

              loop

              do this

              perform find [which means exit find mode] 

              loop 

               

               

              Try this:

              Show custom Dialog(Input #1:firstprint,Input#2:lastprint
              Enter find mode
              Set field (p;firstprint)
              Set Variable($f;Value:firstprint)
              loop
                  exit loop if (p>lastprint)
                  perform find[]
                  Set variable [$f:Value $f+1]
              enter find mode 
                  Set Field[p;$f]
              End loop
               
               Does this help?


              • 4. Re: Find in a script problems continue
                deltatango
                  

                And actually, in the last example I gave you, the script would end in find mode, which is no good, so here it is again, modified:

                 

                Show custom Dialog(Input #1:firstprint,Input#2:lastprint
                Enter find mode
                Set field (p;firstprint)
                Set Variable($f;Value:firstprint)
                loop
                       perform find[]
                    Set variable [$f:Value $f+1]
                exit loop if (p>lastprint) 
                enter find mode 
                    Set Field[p;$f]

                End loop 



                • 5. Re: Find in a script problems continue
                  nealt
                    

                  Delta tango:

                  Your suggestions did not work. P never gets into the perform find.

                  • 6. Re: Find in a script problems continue
                    TSGal

                    nealt:

                     

                    Thank you for your post.

                     

                    Are "firstprint" and "lastprint" global fields?  If not, then those values will only be available to the current record when you called the script.  Therefore, store those values to variables.

                     

                    # input your data

                    Show Custom Dialog [ Input #1:firstprint, Input #2:lastprint ]

                     

                    # Make sure lastprint is greater than firstprint

                    If [ firstprint > lastprint ]

                       Halt Script

                    End If 

                     

                    # Store firstprint and lastprint to variables $first and $last

                    Set Variable [ $first ; firstprint ]

                    Set Variable [ $last ; lastprint ]

                     

                    Set Error Capture [On] 

                     

                    # Enter Loop

                    Loop

                     

                       # Search the P field for the value in $first

                       Enter Find Mode []

                       Set Field [ P ; Value: $first ]

                       Perform Find []

                     

                       # make sure there are records to print 

                       If [ Get (FoundCount) > 0 ]

                          <do your print functions here>

                       End If

                     

                       # increment $first

                       Set Variable [ $first ; $first + 1 ]

                     

                       Exit Loop If [ $first > $last ]

                     

                    End Loop

                     

                    Set Error Capture [Off]

                     

                    ---------------

                     

                    The Set Error Capture allows you to trap errors.  I put this in just in case the Find doesn't find a specific value.  You can then skip over this value and move on to the next value.

                     

                    Let me know if you need clarification for any of the above steps.

                     

                    TSGal

                    FileMaker Inc. 

                     

                    • 7. Re: Find in a script problems continue
                      nealt
                        

                      TGAL your solution works!

                      Thanks much.