5 Replies Latest reply on Feb 24, 2011 2:57 PM by wkparkjoe

    Exit Loop If Issue



      Exit Loop If Issue



      I have the following in a script.

      # Clear Quantity
      Set Variable [ $RepNum; Value:0 ]
      Set Variable [ $MaxRep; Value:Count ( Large PO Form::Quantity ) ]
         Set Variable [ $RepNum; Value:$RepNum + 1 ]
         Exit Loop If [ GetAsNumber ( $RemNum ) > GetAsNumber ( $MaxRep ) ]
         If [ not IsEmpty ( Large PO Form::Quantity[$RepNum] ) ]
            Set Field [ Large PO Form::Quantity[$RepNum]; "" ]
         End If
      End Loop

      The idea here is that I have fields I want to blank out. The field above is a 20 repetition field. Based on the logic I'm using, if there are 3 repetitions in the field Quantity, then after the 3rd repetition, exit the loop and move on in the script. However, the script logic above will continue past the condition of the Exit Loop If until it errors out when the field repetition is greater than the max number of repetition (error 111). Any suggestions on why the Exit Loop condition isn't working?

        • 1. Re: Exit Loop If Issue

          "Exit Loop If [ GetAsNumber ( $RemNum ) > GetAsNumber ( $MaxRep ) ]"  I don't see the context of $RemNum.  Is that a typo here, or in your script, or is it called somewhere else?

          • 2. Re: Exit Loop If Issue

            Hmmm, your script assumes that there are no empty repetitions between non-empty repetitions. Not the reason here, but something you may want to keep in mind.

            I do see an error that would explain the problem, but could be just an error made here instead of an error in the original script:

            You are counting reps with a variable named: $RepNum

            But your are testing a variable named: $RemNum in your Exit Loop If step.

            PS. There's a good chance that you can eliminate your repeating field by replacing it with a table of related recrods--which would eliminate the need to count repetitions.

            • 3. Re: Exit Loop If Issue

              Well I'm embarrassed for not catching that. Thank you very much. It was indeed a typo. My eyes were hurting from staring at this for hours just completely missing that I typed it in wrong. Thank you both.

              I couldn't quite come up with logic on checking to first see if the repetition field was empty first. My Exit Loop If condition should handle that (though not the most gracefully). Is there a better way to check first to see if a repetition field is empty? Does the "Not IsEmpty" syntax work? Thank you again for catching that typo.

              • 4. Re: Exit Loop If Issue

                I still recommend against using a repeating field for this in the first place...

                To modify your script, use two variables where you have one. Use one as you do now, but use a second one, incremented inside the If EndIf block to count the actual number of non blank values found and processed.

                Check this second variable to determine when to exit the loop.

                • 5. Re: Exit Loop If Issue

                  Excellent. I'll take a look at changing it to a relational table setup because yes you are absolutely correct. This was an inherrited database so I was just working with what I had at the time. When I have a chance I will definitely create a new table for these repetition fields. Thanks again.