• Global community
• Language:
• Deutsch
• English
• EspaÃ±ol
• FranÃ§ais
• PortuguÃªs
• æ—¥æœ¬èªžã‚³ãƒŸãƒ¥ãƒ‹ãƒ†ã‚£
Dedicated community for Japanese speakers
• í•œêµ­ ì»¤ë®¤ë‹ˆí‹°
Dedicated community for Korean speakers
Exit
• On Adobe XI Pro form tool how do I write a calcula...

# On Adobe XI Pro form tool how do I write a calculation such as excel formula =IFERROR(G14/C14,"")?

New Here ,
Feb 11, 2019 Feb 11, 2019

Copied

On Adobe XI Pro form tool how do I write a calculation such as excel formula =IFERROR(G14/C14,"")? When the form is blank the cell is not acting correctly with a return of zero (\$0.00). Current simple field notation is PV1/OP with the return in a %.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

633

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
14 Replies 14
LEGEND ,
Feb 12, 2019 Feb 12, 2019

Copied

Acrobat allows a programmer to adds JavaScript code to do calculation and verification.  To handle the specific case here you would use getField to read the value of C14, and make sure it isnâ€™t zero before dividing by it.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Feb 12, 2019 Feb 12, 2019

Copied

You can either check if the divisor is zero (or empty) first, or check if the result of the operation equals "Infinity" (no quotes). If that's the case, you know it was the result of division by zero, and then apply another value to it.

Keep in mind, though, that a percentage field can never be empty. Its default value is "0%", which is not always the correct result...

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
LEGEND ,
Feb 12, 2019 Feb 12, 2019

Copied

Did anyone know that this is valid in simplified field notation:

A == 0 ? 0 : B / A

I was susprised, and cannot find a specification...

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Feb 12, 2019 Feb 12, 2019

Copied

No, it's not. You need to use a script.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Feb 12, 2019 Feb 12, 2019

Copied

What would the script be?

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Feb 12, 2019 Feb 12, 2019

Copied

Something like this:

`var v1 = Number(this.getField("Field1").valueAsString);var v2 = Number(this.getField("Field2").valueAsString);if (v2==0) event.value = "";else event.value = v1/v2;`

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Feb 12, 2019 Feb 12, 2019

Copied

Thanks, that has gotten rid of the original issue yet caused another. The field for v1 is gotten by subtracting 1 field from another. Both of these fields are filled in by subtracting two other fields. I am trying to use this for an invoice adjustment sheet for everyone to be able to simply use and the math is done for them. I have the original sell (OS), new sell (NS) these two fields are entered by the company agent. Those two fields are auto-calculated to the invoice variance (IV) box. Then we have the agent enter in the original buy (OB) and the new buy (NB) and those auto-calculate to the buy variance box. The rest of the lines are auto-filled with simple math. original profit (OP) is OS-OB and new profit (NP) is NS-NB. Profit variance (PV2) is new profit - original profit (NP-OP). the last item is profit variance % (PV3). The script corrected the issue for PV3 getting an error when the sheet is blank, the issue now is when profit variance =\$0.00  I get a warning "The value entered does not match the format of the field [PV2]" and then PV3 no longer returns a valid number when it should return 0.00% PV3=PV2/OP. Is what I want to do just too complicated for Adobe java to handle? Thanks for your help.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Feb 12, 2019 Feb 12, 2019

Copied

LATEST

You need to apply the same logic to the other field, too. It's not too complicated for JS; It might be too complicated for someone without the required JS knowledge.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
LEGEND ,
Feb 12, 2019 Feb 12, 2019

Copied

No, I'm saying it IS valid. I tried it in Acrobat X... like all simplified field notation, it compiles directly into JavaScript, and this looks valid to me.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Feb 12, 2019 Feb 12, 2019

Copied

Oh really? Wow... I'll try it myself.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Feb 12, 2019 Feb 12, 2019

Copied

It does work, but the results are not really desired, I think... If both fields are empty the outcome is "NaN", and if A is empty but B is not (and not 0) the result is Infinity. I still think a script is the best way of doing it.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
LEGEND ,
Feb 12, 2019 Feb 12, 2019

Copied

I think you're right. Could go further with

(A+0) == 0 ? 0 : (B+0) / (A+0) )

but it really isn't "simplified". Crucially, I think it would leave beginners more confused, not less...

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
LEGEND ,
Feb 12, 2019 Feb 12, 2019

Copied

The script would be written by a programmer. Would you like resources to learn how to program JavaScript?

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Feb 12, 2019 Feb 12, 2019