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

How do I do simple subtraction??

FogCityNative
Registered: May 14 2009
Posts: 2

I am not a programmer. I am trying to automate some forms to a Financial Statement by adding form fields. Pretty easy basic stuff.

I get how to use the Calculate Tab to ADD fields.

Now I am at the step that I need to calculate Net_Worth = Total_Assets - Total Liabilities.

Basic subtraction . . . . one field minus another field. 5 seconds to do in Excel. Impossible (for me) in Acrobat.

Can someone please show me a simple Calculation or JavaScript to do basic subtraction in Acrobat forms?

I have looked for some examples online but can't get the right syntax to make it work.

I have tried this in Simplified Field Notation:

NetWorth.rawValue = Total_Assets.rawValue - TotalLiabilities.rawValue

That doesn't do anything . . . so . . .

I have tried this in JavaScript which I adapted from here (http://www.acrobatusers.com/tutorials/2006/scripts_form_fields/):

event.value=this.getField("Total_Assets") - this.getField("TotalLiabilities");

But is doesn't work either.

Seems like the simplest thing that it should be easy to find another example or tutorial to watch or copy or find documented in the manual, but alas after two hours I gave up and posted here.

Thanks

My Product Information:
Acrobat Pro 9.1, Macintosh
Merlin
Acrobat 9ExpertTeam
Registered: Mar 1 2006
Posts: 766
Ted's tips are made for you !
You'll find some calculations examples inside.

--> http://www.acrobatusers.com/blogs/tedpadova/101-forms-etips
jadinfrost
Registered: Jun 4 2009
Posts: 3
"To calculate Net_Worth = Total_Assets - Total Liabilities"


I don't know if my approach was the most efficient but it works every time. I am assuming here that the fields you have are names as above. I created a variable and set it to the value of each field. Once this was done I was able to perform the subtraction and set the field to be the result.


// Start Code
// First set variables
var NetWorth = this.getField("Net_Worth");
var TotalAssets = this.getField("Total_Assets");
var Liability = this.getField("Total Liabilities:);

// Then perform operation and save result
NetWorth.value = TotalAssets.value-Liability.value;

// End Code
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Because Acrobat JavaScript is an object orientated language, objects are processed and and not properties, one needs to access properties or use a method of an object to achieve the desired results.

For a computaion, one usually access the 'value' property of an object.

So for a subtraction, one used the '-', subtraction operator, and the 'value' property of a field or a variable. For the 'networth' field one could use the following custom calculation script:

event.value = Number(this.getField("Total_Assets").value) - Number(this.getField("TotalLiabilities").value);
You do not need to specify the 'NetValue' field as you are in that field. The use of the "Number()" constrictor, is to prevent Acrobat JavaScript trying to force a blank to a string and not a number.

George Kaiser