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

Exponents: Raising a number to a power

davidbb
Registered: Oct 23 2007
Posts: 17

I've got a form from which I need to automate annuity payout calculations, based on user input. I'm used to using "^" to raise a number by a power in Excel, but this does not seem to be a recognized operator in LiveCycle.

How do I accomplish this in LiveCycle?

Thanks,
-David

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
You should be able to use JavaScript and the "Math" object's "pow" method.


Math.pow(7,2); // square 7 or raise 7 the 2 exponent

George Kaiser

davidbb
Registered: Oct 23 2007
Posts: 17
gkaiseril wrote:
You should be able to use JavaScript and the "Math" object's "pow" method.Math.pow(7,2); // square 7 or raise 7 the 2 exponent
Thanks, George!

My form is designed totally using FormCalc. Can I use JavaScript for just this one calculation, or can I assume I have to convert the whole shebang?

I can't believe there's nothing available native to LiveCycle. I routinely bang my head on the wall with this product... ;-)

-David
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Yes, you just need to set the scripting language in the script editor from "FormCalc" to "JavaScript".

George Kaiser

davidbb
Registered: Oct 23 2007
Posts: 17
gkaiseril wrote:
Yes, you just need to set the scripting language in the script editor from "FormCalc" to "JavaScript".
Apparently, I can just change the one script to JavaScript without affecting the rest of my document.

Unfortunately, I'm not well-versed in JavaScript or the debugger; I am now getting the following error:

syntax error
4:XFA:topmostSubform[0]:Page4[0]:numOptionQty[0]:exit

What exactly is this trying to tell me regarding my variable "numOptionQty," which is what I'm putting a user-entered value into?

(I've converted a known good FormCalc script to JavaScript to ensure that it would still execute; I have not yet tried your exponent suggestion).

Thanks, again.
davidbb
Registered: Oct 23 2007
Posts: 17
davidbb wrote:
gkaiseril wrote:
Yes, you just need to set the scripting language in the script editor from "FormCalc" to "JavaScript".
Apparently, I can just change the one script to JavaScript without affecting the rest of my document.

Unfortunately, I'm not well-versed in JavaScript or the debugger; I am now getting the following error:

syntax error
4:XFA:topmostSubform[0]:Page4[0]:numOptionQty[0]:exit

What exactly is this trying to tell me regarding my variable "numOptionQty," which is what I'm putting a user-entered value into?

(I've converted a known good FormCalc script to JavaScript to ensure that it would still execute; I have not yet tried your exponent suggestion).

Thanks, again.
An update, George:

When converting my module to Javascript, my numeric field and dropdown boxes ceased taking user input. Apparently, I have to do something JS specific to accept input from the exit event... Not knowing javascript or the debugger, I gave up.

Afterwards, using the JS info you provided, I was further researching FormCalc, and found a way to use exponents. It turns out that there are several undocumented scientific functions as part of the FormCalc spec. They are:

Acos()
Asin()
Atan()
Cos()
Deg2Rad()
Exp()
Log()
Pi()
Pow()
Rad2Deg()
Sin()
Sqrt()
Tan()

I used the pow() function in the exit event of my FormCalc numeric field, and it worked. I read that these functions were part of the 7.1 FormCalc spec; I'm using v8, so they apparently carried over.

I will post this info to the general LiveCycle forum in hopes that others can benefit.

Thanks for your help!

-David
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
I have used JavaScirpt and FormCalc in the same form without problems. When using JavaScript one needs to reference field properties or methods and not just a field name.

$.rawValue = Math.pow(x0.rawValue, y0.rawValue);

Will raise the value of field "x0" to the "y0" power.

George Kaiser