Expand my Community achievements bar.

SOLVED

Inputting a formula

Avatar

Level 2

Im new to acrobat and formcalc.  i'm trying to create a formula which looks like this on excel =66+ (13.7*numericfield1)+(12.7*numericfield2)-(6.8*numericfield3)

if anyone can help me that would be much appreciated

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

If you select the field/object that you want the answer to appear in. Then go to the Script Editor (available from the Window menu if not already open). There is a dropdown where you can select the event that you want to script in, in this case the calculate event.

Your script is close. If you are using FormCalc, then this should work:

$ = 66 + (13.7 * numericfield1) + (12.7 * numericfield2) - (6.8 * numericfield3)

The syntax is slightly different if you are using JavaScript:

this.rawValue = 66 + (13.7 * numericfield1.rawValue) + (12.7 * numericfield2.rawValue) - (6.8 * numericfield3.rawValue); 

Hope that helps,

Niall

Assure Dynamics

View solution in original post

9 Replies

Avatar

Correct answer by
Level 10

Hi,

If you select the field/object that you want the answer to appear in. Then go to the Script Editor (available from the Window menu if not already open). There is a dropdown where you can select the event that you want to script in, in this case the calculate event.

Your script is close. If you are using FormCalc, then this should work:

$ = 66 + (13.7 * numericfield1) + (12.7 * numericfield2) - (6.8 * numericfield3)

The syntax is slightly different if you are using JavaScript:

this.rawValue = 66 + (13.7 * numericfield1.rawValue) + (12.7 * numericfield2.rawValue) - (6.8 * numericfield3.rawValue); 

Hope that helps,

Niall

Assure Dynamics

Avatar

Level 2

Just a follow up question, how do i make the field = zero or empty when there's no data in the previous fields??

Avatar

Level 10

Hi,

You would need to wrap the calculation in an if statement.

This is going to be messy, because I'm not online:

if (numericField1.rawValue != null && numericField2.rawValue != null && numericField3.rawValue != null)

{

this.rawValue = 66 + (13.7 * numericfield1.rawValue) + (12.7 * numericfield2.rawValue) - (6.8 * numericfield3.rawValue);

}

else

{

this.rawValue = 0;

}

This basically checks that all three fields have values first and if that's true, it calculates the answer.

Hope that helps,

Niall

Avatar

Level 2

ok, so do you mean that i would type that in the formula field as well?  if so, before or after the formula?

or is it completely separate?  if this is the case, where do i input it?

Again, many thanks!

Avatar

Level 10

Just to be clear. Do you have the Script Editor open? See this post for a screenshot: http://forums.adobe.com/message/3380790#3380790

The if statement script in the last post included the formula, so this would replace the original suggestion.

The main thing is to select the object and then input the full if/else statement into the calculate event. Make sure to select JavaScript as the language.

If are using Acrobat and not LiveCycle Designer to develop your form then you will need a different solution.

Niall

Avatar

Level 2

Thanks Niall,

am using livecycle and am on the script bar: it has "show","language"& "run at".

i should replace the old reply with the new one?

Avatar

Level 10

Hi,

That is correct. Here is an example:

https://acrobat.com/#d=9zLMzsGsx45FpDD*Hj53Xg

Parallels Desktop.png

Objects and referencing objects in LC Designer is case sensitive! Between the two posts I used "numericfield" and "NumericField". This was a mistake and in a real form the script would have failed.

Hope that helps,

Niall

Assure Dynamics

Avatar

Level 2

Thanks for your help the other day!