8 Replies Latest reply on Feb 5, 2015 2:29 PM by try67

    Formula for if and then statements

    gc21244600

      hello, please excuse my lack of knowledge in this field. What I want to do is create a very simple form. I named 4 boxes: a, b, c, and d. Box a gets an end result out of other boxes (let's just say 1,2,3 with a value of 1 each totaling 3)... and box b is a set value... let's say 100.  Now box c should be that you subtract box b from box a... if box a is less than box b then I want that value to be put into box c. If however box a is negative as a result of b minus a then I want the value of box b to be used in box c. Make sense? I really, really hope there's a genius somewhere out there. Thank you so much in advance for your time and assistance

       

      BY the way, I validated the box in field c calculating that if box b minus a was zero then to not put a negative number. I do however want the number if it's positive (b minus a) but not if a is more than box b.

       

      Example:

       

      Box a = 101

      Box b = 100 (always a set amount and read only field)

      Box c = b minus a = -1 so I want it to show zero because it's a negative number

       

      Example 2:

       

      box a =63

      box b =100

      box c = 63 (because I want the lesser value of box b of box a.

       

      Box d = (other box - let's say 1 w/ a value of 200) minus box c

       

      sprru if this isn't clear. Thank you

        • 1. Re: Formula for if and then statements
          try67 MVP & Adobe Community Professional

          Custom calculation script for "c":

           

          var a = this.getField("a").valueAsString;
          var b = this.getField("b").valueAsString;
          if (a=="" || b=="") event.value = "";
          else { a = Number(a); b = Number(b); event.value = (a>b) ? 0 : a; }
          
          
          

           

          I don't really understand what the calculation for "d" should be...

           

          Edit: fixed code..

          • 2. Re: Formula for if and then statements
            gc21244600 Level 1

            try67 - Thank you sooooooo very much for uour kind help! It seems we're 95% there!!! The fotmula worked perfectly for half of it but not the other half.

             

            example:

             

            box a gave me a value of 66 as a result of box 1 and box 2 (assumed)

            box b is fixed at 100

            box c did take box a since it is less than box b however what I need is when you subtract b from a and it gives you a minus number to take what's in box b.

             

            so let's say I have 200 in box a and 100 in box b, then the answer would be -100... so instead of even putting zero I want it to just take the amount in box b, I hope that makes sense and sorry for mumbling, I've been awake for over 24 hours and I'm not even 1% as smart as some people here. I am so very grateful for your assistance!

            • 3. Re: Formula for if and then statements
              try67 MVP & Adobe Community Professional

              Make sure you use the latest version of the code. I had changed it once or

              twice already...

              • 4. Re: Formula for if and then statements
                gc21244600 Level 1

                i did, I have adobe acrobat 9.  the formula worked perfect for the less option but I will double check once I get home, Im sure I'm wrong.

                 

                i wonder if the first equation is messing things up. Thanks for all your help!

                • 5. Re: Formula for if and then statements
                  gc21244600 Level 1

                  Hello try67:

                   

                  it seems I tried your formula and maybe it's acrobat 9 that doesn't accept the code.

                   

                  Im doing the following:

                   

                  boxes are as follow (and I just edited the names of the boxes correctly)...

                   

                  a + b = c (the sum of box c will always be a positive number from box a + b unless if subtracted from box d makes it a negative number)

                   

                  d-c = e

                   

                  box d will always have a value of 100... 140 to be exact.

                   

                  box c is the result of box a + b

                   

                  if box d is more than box c then box c's sum will be the number used unless it is a negative number in which case box d's amount will be used.

                   

                  on your formula I get the lesser sum... in my example is 66 which is less than 140 however when the number goes into being negative or higher than 140 it won't auto populate 140 in the field. Trust me when I say that I know this sounds retarded... granted I didn't come up with the formula, it's just how it is being requested. I guess logic goes out the window here but I figured maybe, just maybe there's some sort of method of achieving that craziness. Thank you in advance for your patience and assistance!

                  • 6. Re: Formula for if and then statements
                    try67 MVP & Adobe Community Professional

                    Can you share the file in question, via Google Drive, Acrobat.com, Dropbox,

                    or by email?

                     

                    On Thu, Feb 5, 2015 at 10:43 PM, gc21244600 <forums_noreply@adobe.com>

                    • 7. Re: Formula for if and then statements
                      gc21244600 Level 1

                      yes, can I email you? I've never done this. I will be able to do it in 5 hours from now. Sorry, I stepped away and no rush needed and again, all your help is appreciated!!!

                      • 8. Re: Formula for if and then statements
                        try67 MVP & Adobe Community Professional

                        Yeah, I'll send you my address via PM.