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

Mathmatical calculation

tlcollins
Registered: Oct 20 2008
Posts: 13
Answered

I have an excel table that I am bringing over to Acrobat 9 to create a form. There is a large calculation that I need to enter, and my java script knowledge is very limited. How would you write this in Java?

This is the Excel Calculation:

=+((((C7*3.14159)/200)^2)+(((D7*3.14159)/200)^2))*E7

Hope you can help!!

Thanks in advance

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Assuming you name your fields in Acrobat the same as the cell names in Excel, the custom calculation JavaScript for the calculated field could look something like:
// Get the field values, as numbersvar c7 = +getField("C7").value;var d7 = +getField("D7").value;var e7 = +getField("E7").value; // Calculate this field's valueevent.value = e7 * (Math.pow(c7 * Math.PI / 200, 2) + Math.pow(d7 * Math.PI / 200, 2));

George
tlcollins
Registered: Oct 20 2008
Posts: 13
Thank you George!

This is what I have entered:

// Get the field values, as numbers
var Top Diameter1 = +getField("Top Diameter1").value;
var Butt Diameter1 = +getField("Butt Diameter1").value;
var Log Length1 = +getField("Log Length1").value;

// Calculate this field's value
event.value = Log Length * (Math.pow(Top Diameter* Math.PI / 200, 2) + Math.pow(Butt Diameter * Math.PI / 200, 2));


But I keep getting the error:

missing ; before statement 2: at line 3

I think I need a course...
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You cannot have spaces in JavaScript identifiers, so you'd have to change your code to:
// Get the field values, as numbersvar Top_Diameter = +getField("Top Diameter1").value;var Butt_Diameter = +getField("Butt Diameter1").value;var Log_Length = +getField("Log Length1").value; // Calculate this field's valueevent.value = Log_Length * (Math.pow(Top_Diameter * Math.PI / 200, 2) + Math.pow(Butt_Diameter * Math.PI / 200, 2));

Now you've got me thinking about log houses...

For a course on Acrobat JavaScript, consider what's available at www.pdfscripting.com

George
tlcollins
Registered: Oct 20 2008
Posts: 13
That was it! Thank you so much for your help.

Not many log houses being built lately, that's for sure!