3 Replies Latest reply on Feb 22, 2017 11:45 AM by philmodjunk

    Loop Fault


      I'm getting stuck in a loop until I hit the "esc" key.


      I have a button on a main menu that triggers a script.

      The script opens a layout, performs a find and goes to the first record in the set.

      It then loops to evaluate contents of a field.

      The field just tracks which records have been used and which have not. Each time a person views and uses the record, a "1" is put in this field by clicking a button which also advances them to the next record. If they wish to escape to the main menu, they can do so, but the next time they enter this category I want them only to find the unviewed records.

      There is another field that counts the "1"s in the first field; when this field equals 6 (the total number of found records, it dumps back out to the main menu.

      It all works fine EXCEPT when I run the script, it gives me a blinking "ESC" message. When I press "ESC" the layout comes up and everything works perfectly.

      Here's the script:


      Go to layout ["Round 1 News" tblTWQuestions)]

      Perform Find [Restore]  - this pulls up the specific records by category and "round"

      Go to Record/Request/Page [First]


           Set Field [tblTWQuestions::NewsUse] - this is the "tally" field that records a "1" if the question has been used

           If [tblTWQuestins::NewsUse = 1]

                go to Record/Request/Page {Next; Exit after last]

           End If

      End Loop


      This script is just to get the proper records into the layout - those that only have "1" in the "NewsUse" field.


      As I said it works after I hit "esc"; I had inserted a "halt script" command after the End If, but it didn't pull up the correct records.


      I went to post this in the "beginner's forum" but it won't let me post a new discussion and looks to be abandoned.

        • 1. Re: Loop Fault

          Whenever you start to create a loop, always include an "exit loop if" step. In this case, you'll only ever exit the loop if the NewsUse = 1 and it is the last record. If the NewsUse does not equal one, which will happen for all the records you want the user to see, there is no way to exit the loop. Your IF needs an ELSE.



               go to record next [ next, exit after last ]


               exit loop [ true ]

          end if

          1 of 1 people found this helpful
          • 2. Re: Loop Fault

            So where do I send the adult beverages / free dinner / trip to the bahamas?


            Thank you so much!@

            • 3. Re: Loop Fault

              Instead of looping, constrain the found set to only those records that don't have that 1. Faster, simpler and if you get a found set of 0, you know that the user has viewed all records in the set.