These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

FormCalc issue when calculating percents

radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Answered

Hello,

I've got a problem with some percent calculation in a form.

The following script always causes an error message when opening the form.
But the script for the field "success" works as I want it to.

**************************************************************
round(100 / Form1.Page1.Body.Counters1.SUM1 * Form1.Page1.Body.Counters2.SUM2, 2)
**************************************************************

The error message is german, so i try to translate it:
**************************************************************
Script failed: (Language is FormCalc; Context is xfaform[0]...Form1.Page1.Body.Success
Script is: round(100 / Form1.Page1.Body.Counters1.SUM1 * Form1.Page1.Body.Counters2.SUM2, 2)
Error: Arithmetic Over-/Underrun
**************************************************************

I found nothing about this error on adobe's websites, FormCalc manuals or google, that was helpful.
Is there a way to hide the error message or even a solution for the error itself?

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
What is the value of Sum1?

Now, what is the value of 100 or any number divided by zero?

You need to preform a logical test for a zero value and then decide how to handle that situation.

George Kaiser

radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Ok,

thanks for your hint gkaiseril!
The values auf SUM1 and SUM2 can be any number the user type in.
SUM1 is the whole amount of done phone calls for example and SUM2 the number of calls that has been successfully solved.

The field "Success" is to calculate the ratio of successfully calls.
A simple calculation I think.
And for 100 / 0 * 0 the result is 0 and should not cause an error like this.

Anyway, I have replaced the FormCalc-Script with JavaScript, that works in the same way, but without any error.

**************************************************************
var SUM1 = Form1.Page1.Body.Counters1.SUM1 .rawValue;
var SUM2 = Form1.Page1.Body.Counters2.SUM2 .rawValue;

event.value = (100 / SUM1) * SUM2;

**************************************************************

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Overflow/underflow refers to computing a value too large or small for the language/computer to process. In the past, this type of calculation would send the arithmetic control units into an infinite loop which required a hard shutdown and restart.

I would expect you really need to use an "if" statement to make sure you do not have a zero value for SUM1. Just for good coding practices because other languages may not work like JavaScipt in LiveCycle Designer.


var SUM1 = Form1.Page1.Body.Counters1.SUM1 .rawValue;
var SUM2 = Form1.Page1.Body.Counters2.SUM2 .rawValue;

if(SUM1 != 0) {
event.value = (100 / SUM1) * SUM2;;
} else {
event.value = '';
}

George Kaiser

radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Well,

that makes sense.
Thanks for your explanation!

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs