7 Replies Latest reply on Oct 25, 2013 1:43 AM by xtremu

    Simple Calculator Script

    xtremu

      Title

      Simple Calculator Script

      Post

           Hi guys,

           Please help.

           I want to make a simple calculator that shows the number results and text results. I have 4 fields, number1,  number2, numberresults all of this is number field while the text result field is text field.

           My problem is when the results are more than 50 up to 100, it did not show the corresponding text results (moderare high or high). I dont know why? tried to used CASE script but I dont know how to make it..hope you help me solve this simple problem..

           tried to browse FM forums but no luck to find it..

           please refer to the screenshot below.

           Thanks...

      screenshot.jpg

        • 1. Re: Simple Calculator Script
          gcatnine

               wrong if test.

               Correct

               if ( calculator::NumberResult > 25 and calculator::NumberResult < 51)

                

               and so on...

          • 2. Re: Simple Calculator Script
            xtremu

                 Thanks Gianandrea Gattinoni, I will try it later when I got home..

                   
            •           
                               
              •                      
              •           
                   
            • 3. Re: Simple Calculator Script
              philmodjunk

                   Note: You could use a single set field step and put a case function with this logic as the second parameter of the set field step. That would reduce this script to just two lines of code.

              • 4. Re: Simple Calculator Script
                xtremu

                     Hi Gianandrea Gattinoni, I follow your suggestion but it doesn't work here, it performs the mathematical operations but shows only the (LOW) results in the text results field, the rest did not appear. below is the script..

                     By the way phil, how to make CASE function here? Please help...

                     xtremu

                • 5. Re: Simple Calculator Script
                  gcatnine

                       In your structure everything is included in the main if. So, you enter in the if only when is true (that means only when in below 26).

                       Here the correct one:

                       if ( calculator::NumberResult < 26)

                                       SetField [calculator::TextResult; “Low”]

                       ElseIf ( calculator::NumberResult > 25 and calculator::NumberResult < 51)

                                       SetField [calculator::TextResult; “Ave”]

                       ElseIf ( calculator::NumberResult > 50 and calculator::NumberResult < 76)

                                       SetField [calculator::TextResult; “Moderate High”]      

                       ElseIf ( calculator::NumberResult > 75 and calculator::NumberResult < 101)

                                       SetField [calculator::TextResult; “High”]

                       Else

                       “out limits”

                       EndIf

                        

                       The case statement is:

                       setField [calculator::TextResult;

                                       Case(

                                       calculator::NumberResult < 26 ; “Low”;

                                       calculator::NumberResult > 25 and calculator::NumberResult < 51; “Ave”;

                                       calculator::NumberResult > 50 and calculator::NumberResult < 76; “Moderate High”;

                                       calculator::NumberResult > 75 and calculator::NumberResult < 101; “High”;

                                       “out limits”)]

                        

                       It is always a good practice when you have a set of defined tests (as in your case) to check if there is a wrong data (“out limits”)

                                     

                  • 6. Re: Simple Calculator Script
                    philmodjunk

                         The case function returns the associated result for the first expression to evaluate as true, thus the case function can be further simplified to be:

                         Case(
                                         calculator::NumberResult < 26 ; “Low”;
                                         calculator::NumberResult < 51; “Ave”;
                                         calculator::NumberResult < 76; “Moderate High”;
                                         calculator::NumberResult < 101; “High”;
                                         “out limits”
                                  ) // Case

                    • 7. Re: Simple Calculator Script
                      xtremu

                           Thanks  Gianandrea Gattinoni and Phil.. It's working fine now..