6 Replies Latest reply on May 7, 2008 5:27 AM by (Suzy_Q)

    IFF statement

      I am trying to IFF statment in abode 8 to calculate reimburse amount, this is what I have:
      var cent=((event.value<01/01/08)? 0.485:0.505);
      If the value is less then Jan 1st then use .505 else use .485. Be default it uses .485 for calcuation. However when i tab to the next column then it uses .505. I am not able to figure out why it is doing so.
        • 1. Re: IFF statement
          gkaiseril MVP & Adobe Community Professional
          You have to code the string date you want to compare to as a string and not a formula. That is you have to enclose the date string within parenthesis.

          The format for the conditional operator is:

          condition ? expr1 : expr2

          where if the condition is true expr1 is used (returned) and false expr2 is used (returned).

          Also, you should convert the date string value into a JavaScript date time object by using the "util.scand()" method and then compare the date time object to a values using the ".valueOf()" method to get the number of milliseconds since 1/1/1970. as this will prevent errors if date formats are changed.

          var oDateCutoff = util.scand("mm/dd/yy", "01/01/08");
          var oFormDate = util.scand("mm/dd/yy", event.value);
          var cent = oFormDate.valueOf() < oDateCutoff.valueOf()? 0.5050 : 0.4850;

          You are comparing the value strings of the event.value and the provided text string. The comparison would only evaluate to true for dates after 1/1/2008 that were entered with leading zeros and false if leading zeros were not entered into the form field.
          • 2. Re: IFF statement
            Level 1
            Thanks Kaiser, it is working as it I expected it to be.
            Happy New Year!
            • 3. Re: IFF statement
              Geo,

              Can you help me adapt this to my form as I realize I will probably need this when the IRS adjusts the mileage reimbursement rate in January of each year?

              On my form, I have a form field called "TravelBegin", which is what would trigger the change in the rate. I have a field on my form labeled "Miles" where employees enter the amount of miles driven. I have a third field labeled "TotalMileage" which should automatically calculate the number of miles times the correct rate depending on the value of the Travel Begin date.

              I was using the following formula to calculate the rate, but I think I should change it as I could be working with two different rates at one time. How should I adapt this to use the date condition example you gave?

              var Miles=this.getField("Miles").value;
              var Multiplier=.505
              event.value=Number(util.printf("%.2f", Miles*Multiplier));

              By the way, I am not very experienced in Javascript or any other language. I was thrown into a project and feel I have learned a great deal from your posts. Thank you (even if you don't respond to this post) for all of the help you given to people like me. With the help of you and few others, I've been able to complete most of my project.
              • 4. Re: IFF statement
                gkaiseril MVP & Adobe Community Professional
                Since date entries do not lend themselves to comparisons, sort orders, computations, etc, one needs to convert the inputted date string to a numeric value based on a standard starting date. use of the "util.scand()" method is one way to convert a date string to the standard JaveScirpt date object, not a number but easily converted to a number. This data number in JavaScript is the number of milliseconds from midnight January 1, 1970. Once this number is obtained for a given pair of numbers, one can easily do comparisons and other actions.

                The following script is one method to use the begin travel date to compute the mileage dollar amount.

                function ComputeMilageCharge(fTravelBegin) {
                /* compute mileage charge using the date travel began and
                the last date for which the mileage rate was valid
                */
                // variable for the mileage charge
                var fCharge = ""; // variable for mileage charge - null string is an invalid date

                // use end dates for mileage rates starting at the latest end date
                // travel starts during last rate period
                if ( fTravelBegin <= Number(util.scand("mm/dd/yyyy", "12/31/2008")) )
                fCharge = 0.510 * this.getField("Miles").value;

                // mid year change date and rate
                if ( fTravelBegin <= Number(util.scand("mm/dd/yyyy", "05/01/2008")) )
                fCharge = 0.505 * this.getField("Miles").value;

                // date before code supports
                if ( fTravelBegin < Number(util.scand("mm/dd/yyyy", "01/01/2008")) )
                fCharge = "";

                // test for invalid date entry
                if (fCharge == "")
                app.alert("The beginning travel date is outside the forms date coverage", 1, 0);

                return fCharge;
                } // end ComputeMilageCharge

                // compute only if there is a begin date
                if(this.getField("TravelBegin").value != "")
                // call function is numeric value of travel begin date
                event.value = ComputeMilageCharge( Number(util.scand("mm/dd/yyyy", this.getField("TravelBegin").value)) );
                • 5. Re: IFF statement
                  Level 1
                  Thanks Geo,

                  Sorry it took so long to get back to you. I had a few emergencies (computer crashed and I had to take my dog to the vet). I appreciate your help!
                  • 6. Re: IFF statement
                    Level 1
                    Geo,

                    Thanks much!!!!!! I copied this into my form and got an unterminated comment error - but I figured it out and it works beautifully. You're wonderful!