4 Replies Latest reply on Apr 2, 2012 4:18 PM by BMarshall9

    Need some help with converting an excel formula.

    BMarshall9

      I really seem to be having a problem wrapping my mind around Java.  Could someone maybe help me with this particular formula?

       

      What I am trying to do is convert a Modern D20 Character sheet I designed in Excel.  The excel version looks like this:   =ROUNDDOWN((C11)/2-5,0).

       

      Also, how easy is it to link to fields together so that the result of the above equation appears in the right place in the "skills" modifier field else where on the page?

       

      Thank you for any help you may provide!

       

      Blair Marshall

        • 1. Re: Need some help with converting an excel formula.
          George_Johnson MVP & Adobe Community Professional

          The JavaScript that you would place in Calculate event of a field would be something like this:

           

           

          // Custom Calculate script for text field
          (function () {
          
              // Get the field value of C11, as a number
              var v = +getField("C11").value;
          
              // Perform the calculation, round down, and set this field's value
              event.value = Math.floor(v / 2 - 5);
          
          })();
          

           

          Replace "C11" with the actual name of the field if it's different.

           

          If you give fields the same name, they will automatically get the same value.

          • 2. Re: Need some help with converting an excel formula.
            BMarshall9 Level 1

            One more question I think.  How do I save and distribute this form so that my fellow Players in this campaign can fill it out and save the filled out form on their computer if they are only using reader 9?  ANd finally....what would I add to that equation to aloow it to output a "0" if the result of the formula is zero or less?

            1 person found this helpful
            • 3. Re: Need some help with converting an excel formula.
              George_Johnson MVP & Adobe Community Professional

              You will need to Reader-enable the document. If you have Acrobat 9, select: Advanced > Extend Features in Adobe Reader. If Acrobat 10, select: File > Save As > Reader Extended PDF > Enable Additional Features

               

              To set the value of the field to zero of zero or less, the script would be:

               

              // Custom Calculate script for text field
              (function () {
              
                  // Get the field value of C11, as a number
                  var v = +getField("C11").value;
              
                  // Perform the calculation, round down, and set this field's value
                  var val = Math.floor(v / 2 - 5);
                  event.value = val > 0 ? val : 0;
              
              })();
              
              1 person found this helpful
              • 4. Re: Need some help with converting an excel formula.
                BMarshall9 Level 1

                Awesome, Thank you Very Much for the help!!

                1 person found this helpful