5 Replies Latest reply on Sep 19, 2014 9:35 PM by nihmbrisby

    Inequalities with local variables in Exit Loop Statements

    nihmbrisby

      Title

      Inequalities with local variables in Exit Loop Statements

      Post

      One weird and persistent problem I've had over months of development is as follows:

      I define local variables (ie $counter = 1 and $end=10) in the beginning of the script.  I set up a loop.  I increment the counter (ie $counter = $counter +1).  I create an exit loop if () statement.  The statment is simply $counter>$end.  

      This consistently exits the loop when the counter is less than end.  I stare at the data viewer till my eyes bleed:

      $counter=2

      $end=10

      Exit Loop if ($counter>$end)

      And every time- the loop is exited when $counter = 2 (that is to say, the loop repeats once).  If I do *nothing* more than change ">" to "=" the script works perfectly.  I get the same problem with greater than or equals to.

      I'm close enough to the finish line that I just don't have the stamina to investigate this further.  Nevertheless, I just wanted to throw this out there to see if anyone had any ideas.  My only idea is that filemaker may be treating local variables as text, not numbers.

      At the moment I simply do not use inequalities in control statements.

       

      Thanks!

        • 1. Re: Inequalities with local variables in Exit Loop Statements
          raybaudi

          This is a tipical error of numbers interpreted as text. ( Do you know, Phil ? )

          Try:

          If [ GetAsNumber ( $counter ) > GetAsNumber ( $end ) ]

          • 2. Re: Inequalities with local variables in Exit Loop Statements
            philmodjunk

            It would be useful to see the actual script so we can spot why the data in the variables is treated as text instead of numbers.

            To post a script to the forum:

                   
            1. You can upload a screen shot of your script by using the Upload an Image controls located just below Post a New Answer.
            2.      
            3. You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF to your clipboard for pasting here. (with this approach, you can get multiple script steps on the same line, please edit the pasted text by inserting some returns to separate those steps.)
            4.      
            5. If You have FileMaker Advanced, you can generate a database design report and copy the script as text from there.
            6.      
            7. If you paste a text form of the script, you can use the Script Pretty box in the Known Bugs List database to paste a version that is single spaced and indented for a more professional and easier to read format.
            • 3. Re: Inequalities with local variables in Exit Loop Statements
              nihmbrisby

              Though, as I said, I'm not really in the same place as I was a few months ago to be posting images, scripts, pdf's and what not (time constraints), I will say that variable declaration in scripts clearly states "Calculation must be text" at the bottom (Guess I missed that before).  

              Of course there are many ways around this, but it just strikes me as a little off.  Seems like the type for the calculation results could be specified here, as it is when creating a field calculation.  Not big deal I guess.

              • 4. Re: Inequalities with local variables in Exit Loop Statements
                philmodjunk

                Usually, if the calculation computes a numeric value, the value stored is a number and when compared to other values in a boolean expression such as those found in your Exit Loop If script step, it will evaluate as a number. But if the calculation is set up (by the operators, functions and literal values used) to compute a text value, the value will be stored and evaluated as text.

                Set Variable [ $K ; value: $K + 1 ]

                produces a numeric result that is stored as a number.

                Set Variable [ $K ; value: "Apple " & "Computer" ]

                produces a text result that is stored as text.

                And

                Set Variable [$K ; Value: "12" ]

                produces a text result that is stored and evaluated as text due to the quotation marks used.

                This is why I asked to see your script as this would help us spot what expression is producing a text result that "types" the variable as text rather than a number..

                Also, Raybaudi recalled in another post that it seemed like variables were always text in an older version so if you are using a version older than FileMaker 11, that might also be a factor here.

                • 5. Re: Inequalities with local variables in Exit Loop Statements
                  nihmbrisby

                  Thanks Phil and Ray.

                  The issue was indeed that some of the numeric fields referenced in the calculation that determined the variable were defined as 'text' and not 'number.'