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

Help with Calculations

gadgetman
Registered: Nov 2 2007
Posts: 14

Ok.. I need some help from all you experts here.

What I have is a form similar to the below example where users perform a test and then have to enter the result in the blank under "Test Results". Most, if not all the results begin with a zero (ie: 07). In the properties dialog box, if I choose to format it as a number, it eliminates the zero value which can't happen because it's supposed to be a decimal # (ie: 07 is displayed as just 7). The % signs are also already pre-printed so I cannot format the "Test Results" or Absolute Difference" fields as a % or else it will display as double percent sign because the Percent format includes the % sign. (it displays as . 05 %% )

In the "Absolute Value" column, I need it to perform the calculation (difference) from the other 2 columns and have it be a positive number even if the test result is lower than the constant.

Then I need the TOTAL to calculate the sum of all fields from the Absolute Difference column. The total then needs averaged as you can see.

So... Come on all you experts! How do I get past the zero being eliminated for the NUMBER format or is there a way to format as a Percentage and have it drop the % sign?

Example:
[img]http://homepage.mac.com/gadgetman/.Pictures/001.jpg[/img]

My Product Information:
Acrobat Pro 8.1.2, Macintosh
hiddengraphics
Registered: Mar 19 2008
Posts: 39
JavaScript code will work, I believe

You need an If statement something like If event.val <= 0,
then event.val =-1*event.val

You will need this for each line entered by the respondent.
gadgetman
Registered: Nov 2 2007
Posts: 14
I'm assuming the script above takes care of the "absolute value" column in that it will make any negative # a positive one? is that correct? If so, how do I enter the script and still subtract the "test result" from the "constant"?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Because the "%" is preprinted on the form, you must decide if you want to the use the "percentage" format or not. If you do not us the "percentage" format you will have to adjust you scripts to adjust for the disply by 100 times as greate as it should be. If you want to use the "percentage" format, create a field with a solid white fill color and cover the preprinted "%" sign.

As to the absolute value, one can use JavaScirpt's "Math" object's "abs()" method to get the absolute value of a field or vriable. So you cold have a custom calculation script for the Abosolute Difference field like:

var Result = this.getField("Test Reslult").value / 100; // adjusted for not using the percentage format
event.value = Math.abs(Result - 0.0010);

Assuming that your tes result field is not in the percentage format.

Since this calculation will be used for many fields, consider using a document level JvavaScript function to perform the calculation and return the result of the calculation.

George Kaiser

gadgetman
Registered: Nov 2 2007
Posts: 14
gkaiseril, thank you for the willingness to help me out. I'm a bit lost grrrr (I need more experience w/ this stuff). If I could go step by step it would help I think.

Your scripts above, where should they be put?

Also, what do you mean by "consider using a document level Javascript function". Is that different than placing the script in the calculation portion of the properties?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
The script above can be used in the "custom calculation script" option on the "Calculation" tab for each field in the result. You will have to adjust the script for the specific field names.

As to the use of a function, because of the interative nature of Acrobat'S JavaScript, this type of repetative code can slow the forms interaction down significantly. A way around this is through the use of document level functions that are pre-tokinized at startup and can run repeated code more quickly.

You could use a document level funciton like:

function AbsDiff(fValue1, fValue2) {
// compute absolute difference of fValue1 - fValue2
return Math.abs(fValue1 - fValue2);
}

How to place a document level function:
[url=http://www.acrobatusers.com/tutorials/2007/js_document_scripts//Entering Document Scripts[/ur]by Thom Parker

Your custom calculation script can be:

event.value = AbsDiff(this.getFeidl("Result.0").value, 0.00010);

You will have to change the "Result.0" to the appropriate field name.

George Kaiser