Question Details

avatar
Welcome to the Acrobat Answers site. You're on your way! It won't take you many more points to reach the next level: Participant. And as you accumulate more points, you're also building your reputation with the community and with AcrobatUsers.com.

Custom Calculation Script: Avoid Division by 0. Prevent "Value Entered Does Not Match Format of the Field"

I have been throughout this site and have discovered that I am having a problem b/c Acrobat XI thinks that I could be dividing by zero, however, I do not know what I need to put in my scripts to avoid division by 0.

My scripts work fine as long as I do not change the format from "none" to "number". Bottom line is I need the values to round to one or two decimal places without producing the error.

My scripts are as follows:

event.value = this.getField("DistanceInches1").value / ( this.getField("TimeSeconds1").value / 60 + this.getField("TimeMinutes1").value );

event.value = ( this.getField("LowAmps1").value * this.getField("LowVolts1").value * 60 ) / ( this.getField("IPM1").value * 1000);

In order to clarify, what do I need to have in the script so that I can format the field as a number with decimal(s) and prevent the error.

Thanks in advance.


Quality Testing 421 days ago


2 Answers

Voted Best Answer

avatar
<p>Congratulations! The Acrobat User Community selection team has approved your status as Expert in the Acrobat User Community. We appreciate all your past contributions and hope you will continue to support the community by answering questions and participating in the Acrobat Answers Q&A program as you've done in the past.</p>

<p>As an expert, you will get a badge to display on your profile with the level EXPERT next to your name and you have become eligible to be nominated to the Adobe Community Professional Program.</p>

<p>After reviewing the Adobe Community Professional Program information at https://www.adobe.com/communities/professionals/, please let us know if you are interested.</p>

<p>Someone from the selection team will contact you soon regarding the community professional program. Keep up the good work!</p>

<p>Regards,</p>

<p>The Acrobat User Community Team</p>


<p>**** Disclosure Requirements for Endorsements Received by Third Parties  ****</p>

<p>If you endorse or refer people to the Acrobat User Community in any venue,  it is our responsibility to ensure that you are aware of required compliance with the <a href="http://ftc.gov/os/2009/10/091005revisedendorsementguides.pdf">FTC’s Guidelines</a>. Both you and Adobe can be held liable under federal law for making unsubstantiated claims and for not disclosing your relationship with Adobe. In particular:</p>

<ol>
<li>Always disclose if you have received any type of incentive – free products, promotional items, travel, gifts, payment, and so on from Adobe. The disclosure must be on the same page as the endorsement.</li>
<li>Be truthful. Endorsements should not be misleading. Never make unsubstantiated or exaggerated claims about the benefits of Adobe products or programs. Any statements or endorsements about an Adobe product must be based on upon your actual experience.</li>
</ol>

Thank you again for your support of Adobe and the Acrobat User Community</p>

Another question is, do you need the calculated value to be rounded. Note that the rounded display value may not be the same as the actual field value or the computed value. This difference could cause additional issues if the computed value is used in another calculation.

Since your field appear to have a row or column index, will these calculations be performed more than once with different field values.

Your first equation:

// row / column index
var nIndex = 1;
// field names
var DIName = "DistanceInches" + nIndex;
var TSName = "TimeSeconds" + nIndex;
var TMName = "TimeMinutes" + nIndex;

// get field values as numbers
var DistanceInches = Number(this.getField(DIName).value);
var TimeSeconds = Number(this.getField(TSName).value);
var TimeMinutes = Number(this.getField(TMName).value);
event.value =  ""; // default value for no calculation; 
if(TimeSeconds != 0 || TimeMinutes != 0) {
event.value = DistanceInches / (TimeSeconds / 60 + TimeMinutes); 
// some debugging information for example
console.show();
console.clear();
console.println("Distance inches: " + DistanceInches);
console.println("Time seconds: " + TimeSeconds);
console.println("Time minutes: " + TimeMinutes);
console.println("Result unrounded: " + event.value);
console.println("Result rounded: " + util.printf("%,0 0.2f", event.value));
}

Try different values and observe the results in the JavaScript console to see that the displayed value is not the exact value of the computation or field.


By George Kaiser answered 421 days ago  |   Comments (3)  |  New Comment

avatar
Welcome to the Acrobat Answers site. You're on your way! It won't take you many more points to reach the next level: Participant. And as you accumulate more points, you're also building your reputation with the community and with AcrobatUsers.com.

Ultimately, yes, the value that gets produced from this equation will be used in three other equations on the same row. If you reference my second script, it will be the IPM1 value, but I think I can get away with a rounded value in there. If I understand you correctly, then yes, these calculations will be performed more than once with different field values.

Quality Testing Commented 421 days ago  |   Report


avatar
<p>Congratulations! The Acrobat User Community selection team has approved your status as Expert in the Acrobat User Community. We appreciate all your past contributions and hope you will continue to support the community by answering questions and participating in the Acrobat Answers Q&A program as you've done in the past.</p>

<p>As an expert, you will get a badge to display on your profile with the level EXPERT next to your name and you have become eligible to be nominated to the Adobe Community Professional Program.</p>

<p>After reviewing the Adobe Community Professional Program information at https://www.adobe.com/communities/professionals/, please let us know if you are interested.</p>

<p>Someone from the selection team will contact you soon regarding the community professional program. Keep up the good work!</p>

<p>Regards,</p>

<p>The Acrobat User Community Team</p>


<p>**** Disclosure Requirements for Endorsements Received by Third Parties  ****</p>

<p>If you endorse or refer people to the Acrobat User Community in any venue,  it is our responsibility to ensure that you are aware of required compliance with the <a href="http://ftc.gov/os/2009/10/091005revisedendorsementguides.pdf">FTC’s Guidelines</a>. Both you and Adobe can be held liable under federal law for making unsubstantiated claims and for not disclosing your relationship with Adobe. In particular:</p>

<ol>
<li>Always disclose if you have received any type of incentive – free products, promotional items, travel, gifts, payment, and so on from Adobe. The disclosure must be on the same page as the endorsement.</li>
<li>Be truthful. Endorsements should not be misleading. Never make unsubstantiated or exaggerated claims about the benefits of Adobe products or programs. Any statements or endorsements about an Adobe product must be based on upon your actual experience.</li>
</ol>

Thank you again for your support of Adobe and the Acrobat User Community</p>

I think you might want to check your math. It appears you are trying to compute movement in inches per minute, but that is not what your script is computing.

George Kaiser Commented 421 days ago  |   Report


avatar
<p>Congratulations! The Acrobat User Community selection team has approved your status as Expert in the Acrobat User Community. We appreciate all your past contributions and hope you will continue to support the community by answering questions and participating in the Acrobat Answers Q&A program as you've done in the past.</p>

<p>As an expert, you will get a badge to display on your profile with the level EXPERT next to your name and you have become eligible to be nominated to the Adobe Community Professional Program.</p>

<p>After reviewing the Adobe Community Professional Program information at https://www.adobe.com/communities/professionals/, please let us know if you are interested.</p>

<p>Someone from the selection team will contact you soon regarding the community professional program. Keep up the good work!</p>

<p>Regards,</p>

<p>The Acrobat User Community Team</p>


<p>**** Disclosure Requirements for Endorsements Received by Third Parties  ****</p>

<p>If you endorse or refer people to the Acrobat User Community in any venue,  it is our responsibility to ensure that you are aware of required compliance with the <a href="http://ftc.gov/os/2009/10/091005revisedendorsementguides.pdf">FTC’s Guidelines</a>. Both you and Adobe can be held liable under federal law for making unsubstantiated claims and for not disclosing your relationship with Adobe. In particular:</p>

<ol>
<li>Always disclose if you have received any type of incentive – free products, promotional items, travel, gifts, payment, and so on from Adobe. The disclosure must be on the same page as the endorsement.</li>
<li>Be truthful. Endorsements should not be misleading. Never make unsubstantiated or exaggerated claims about the benefits of Adobe products or programs. Any statements or endorsements about an Adobe product must be based on upon your actual experience.</li>
</ol>

Thank you again for your support of Adobe and the Acrobat User Community</p>

Adding comments to your script will help other understand what you are computing or remind you at a later date what your calculation does.

George Kaiser Commented 421 days ago  |   Report


avatar

  |   Report
Was this answer helpful?  
1
0

avatar
<p>Congratulations! The Acrobat User Community selection team has approved your status as Expert in the Acrobat User Community. We appreciate all your past contributions and hope you will continue to support the community by answering questions and participating in the Acrobat Answers Q&A program as you've done in the past.</p>

<p>As an expert, you will get a badge to display on your profile with the level EXPERT next to your name and you have become eligible to be nominated to the Adobe Community Professional Program.</p>

<p>After reviewing the Adobe Community Professional Program information at https://www.adobe.com/communities/professionals/, please let us know if you are interested.</p>

<p>Someone from the selection team will contact you soon regarding the community professional program. Keep up the good work!</p>

<p>Regards,</p>

<p>The Acrobat User Community Team</p>


<p>**** Disclosure Requirements for Endorsements Received by Third Parties  ****</p>

<p>If you endorse or refer people to the Acrobat User Community in any venue,  it is our responsibility to ensure that you are aware of required compliance with the <a href="http://ftc.gov/os/2009/10/091005revisedendorsementguides.pdf">FTC’s Guidelines</a>. Both you and Adobe can be held liable under federal law for making unsubstantiated claims and for not disclosing your relationship with Adobe. In particular:</p>

<ol>
<li>Always disclose if you have received any type of incentive – free products, promotional items, travel, gifts, payment, and so on from Adobe. The disclosure must be on the same page as the endorsement.</li>
<li>Be truthful. Endorsements should not be misleading. Never make unsubstantiated or exaggerated claims about the benefits of Adobe products or programs. Any statements or endorsements about an Adobe product must be based on upon your actual experience.</li>
</ol>

Thank you again for your support of Adobe and the Acrobat User Community</p>

Acrobat does not "know" about any of the numbers you are using in your calculation. JavaScript is like any other programming language: You have to either make sure that you have valid data, or you need to catch the exception that JavaScript throws when the error occurs.

I usually do something like this:

var a = this.getField("DistanceInches1").value;
var b = this.getField("TimeSeconds1").value;
var c = this.getField("TimeMinutes1").value;

if (b != "" && b != 0)
{
    event.value = a/b + c;
}
else
{
    event.value = "";
}

If you would be dividing by 0, you would end up with an empty result field.

Karl Heinz Kremer
PDF Acrobatics Without a Net
PDF Software Development, Training and More...
http://www.khkonsulting.com


Karl Heinz Kremer answered 421 days ago  |   Comments (1)  |  New Comment

avatar
Welcome to the Acrobat Answers site. You're on your way! It won't take you many more points to reach the next level: Participant. And as you accumulate more points, you're also building your reputation with the community and with AcrobatUsers.com.

First, thanks for your quick reply. Now, in this case, I need "b" to be divided by 60 and the equation to look like this: a/(b/60) + c, however, when inserted /60 into this example I get no result. How do I get the field to produce a results once I begin inserting data?

Quality Testing Commented 421 days ago  |   Report


avatar

  |   Report
Was this answer helpful?  
0
0


Download
Acrobat XI trial

Get the trial now


Other Questions Needing Answers