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

Calculations not being saved

greeves
Registered: Jan 14 2008
Posts: 6

I've created a simple form with text fields which calculate a very simple average. When first created, it performs the calculations properly. However, once saved and re-opened, the form, while still showing the calculations in the text field properties, no longer will calculate the average. I'm using Acrobat Professional 8.1.1.

Thanks.

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Can you provide more information.

Acrobat 8 Professional can create forms with the Acrobat Form Tool or by using the LiveCycle Designer. Each product works differently and are not compatilbe at the design level.

What is the method or script for the creation of the average and where have you placed the code?

George Kaiser

greeves
Registered: Jan 14 2008
Posts: 6
I really took the simple approach (or at least I thought). I used the Forms tool in Acrobat and have a column of text fields with the average calculated in the bottom of those fields. All fields are formatted as numbers with a single decimal place. To figure the average, I used the calculate tab in the field properties for the averaging field, chose "average" in the drop down, and selected the corresponding fields from which to draw the numbers to be averaged. When I test it initially, it averages correctly, but once saved it fails.

Thanks.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
And how exactly does the calculation fail? Is there an application error of some kind?

When I tested the "average of" with 4 fields. And tested before saving by entering cell by cell and observing the result. Entering "1" into the first cell computed an average of "0.3", the rounding of 0.25, instead of "1". Blank fields or fields that do not have a number including zero should not be taken into account for the computation of the average. The same problem occurs after the form is saved.

The only way around this is to use the "Custom Calculation" script and not count the blank fields in the calculation.

// following function can be used as a document level function
function Average() {
/*
Purpose: compute the average of the numeric fields with non-blank values
Input: field names to use for the computation
Returns: the average of non-blank numeric fields or zero
*/

var fSum = 0; // sum of fields
var fCount = 0; // count of non-blank numeric fields
var fAverage = 0;

// loop through passed field names
for (i = 0; i < arguments.length; i++) {
// if a number (test typeof field value) then sum and count the field
if (typeof this.getField(arguments[i]).value == "number") {
fSum += this.getField(arguments[i]).value;
fCount++
} // end typeof value
} // end loop
// compute average only if there are numeric items
if (fCount != 0) fAverage = fSum / fCount;
return fAverage;
} // end of function

// custom calculation for field
event.value = Average("fValue.0", "fValue.1", "fValue.2", "fValue.3");

George Kaiser

greeves
Registered: Jan 14 2008
Posts: 6
That's what's troubling. When the form is saved and values are placed in the fields as before, the averaging field simply doesn't react. There is no error message, but the averaging field remains with a value "0.0". The only way that I've been able to get it to average again is to edit the text field properties by changing to "Value is not calculated", then back to "Value is average of the following fields" and reselecting the fields to be averaged. Unfortunately, once it's saved I'm back to square zero. I'd like to think it's something simple that I've overlooked, but can't seem to put a finger on it.

What should make the matter even simpler is that since we will be requiring a value in each of the fields from 0 to 100 (it's an elementary grade report). With zeroes entered, the intial test calculates correctly.

Thanks.
lmretep
Registered: Jan 10 2010
Posts: 1
I’ m new to working with Acrobat 9 Pro forms and JavaScript
I need to exclude blank fields from the average. Is there a way to assign a default null value to the blank that I have set as the default entry so that it will not be included in the average?
Details:
On my form, students have five boxes to enter the grades which they have received in certain courses. I used a combo box to assign export values to each grade e.g. A is 4, B is 3, C is 2 and F is 0 so zero is a valid export value. The default entry is blank.
I set up a field (named GPA) and on the calculated tab I put “Value is the Average of” the following fields: Grade1ComboBox, Grade2ComboBox, Grade3ComboBox, Grade4ComboBox, Grade5ComboBox
That worked perfectly to calculate the average of all 5 fields.
However, some students only have two courses to enter grades for. Therefore I need to exclude blank fields from the average. Is there a way to assign a default null value to the blank that I now have as the default entry so that it will not be included in the average?
Or will I need to use a custom calculation script which will exclude blank fields from the average?

Thanks
Josman
Online
Registered: Jul 15 2009
Posts: 31
I need some help
I created a form in Acrobat 9 pro, and I did some decimal calculation, but is not giveign me a real number.
for example field A = 1.86
field B = 0.19, the Total should be 2.05, instead is giveng me 2.04.
my two field are selected with two decimal in the format tab. Also the Total field is selected two decimals in the format tab. I am using the calculate value is the...sum(+).
thanks.
J

Josman

krickett47
Registered: Feb 4 2010
Posts: 18
I have the following calculation that doesn't work after exiting the form and returning:

this.getField("201").value = this.getField("200").value / this.getField("213").value;

201 is formated as a percentage
200 is formated to a number
213 is formatted to sum two nubmers

I am trying to get a percentage of a number (200) divided by a total of numbers (213).

When I exit the form and go back in to enter 0 in the number fields the percentage calculation does not work anymore, and I get formatting error messages. Can you help?