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

Formcalc to divide

Ghosttek
Registered: Jul 9 2008
Posts: 5

I am trying to use FormCalc in LiveCycle designer 8 to create to divide to fields. according to help, it says to use the Mod function. When I do this, the formulae does not divide, it just transfers the first number to the new line. I have tried different to make it work, but I have not been successful.

Any suggestions would be greatly appreciated.

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
The "Mod" function return the "Modulos" or remainder for a division of the passed value by the passed divisor. The "/' is the divide operator for FormCalc and JavaScript in LiveCycle Designer.

George Kaiser

Ghosttek
Registered: Jul 9 2008
Posts: 5
Thank you for the information. I have used the "/" symbol in my calculation and now i am getting the error: arithmetic over/underflow.

Thanky ou for the information. Now I need to figure out what I am missing.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You can not divide by null or zero.

George Kaiser

Ghosttek
Registered: Jul 9 2008
Posts: 5
Thanks you. When I skipped over the error message and put a second value in, the calculation worked. How do I keep it from trying to calculate until I out that second value in?

I really appreciate your help.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Use the "HasValue()" function in an "if ...then ...else ..endif" statement.

if(HasValue(divisor)) then
dividend / divisor
else
null
endif

George Kaiser

ndjustin20
Registered: Oct 7 2009
Posts: 21
How can i do this with multiple fields. Say i have three fields. One is X and is the dividend and one is Y and that is the divisor and Z is the field that i am placing the result. All the fields are numeric and i want to write a function so that:

if(HasValue(XField) && (HasValue(YField))then
var rent = Xfield.rawValue;
var sqft = Yfield.rawValue;
ZField.rawValue = rent / sqft;
else
Zfield = "0"



For the life of me this should work but i can't get it to check both X and Y for values?????

Justin
ndjustin20
Registered: Oct 7 2009
Posts: 21
I am using livecycle designer 8.0. I'm not sure if that is relevant for the js or not
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Hi Justin,

your script has some faults.
You forgot the terminate the if expression with "endif".
And the operator for a logical AND is not "&&", it's only "&" or "and".
You used 2 different spelling for the field "Zfield" - "ZField", so the script is adressed to two different fields.

I made some corrections. The code can be placed directly into the ZField calculate:event.
if (HasValue(XField) and HasValue(YField)) thenvar rent  = XFieldvar sqft  = YField$.rawValue = rent /sqftelse$.rawValue = 0endif

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

ndjustin20
Registered: Oct 7 2009
Posts: 21
Ok......I am actually writing javascript and && is the "and" operator so I can't use "&" or "and" from what I have ever coded. The only reason I wrote it like that is I couldn't post the actual code as I hadn't posted enough times to use script apparently. I have hit number 10 now so I am posting the actual code I am using. Here is the actual code I am using in javascript:function figurePSF(){

if(HasValue(NumericField13) & (HasValue(NumericField27)){var rent = NumericField13.rawValue;
var sqft = NumericField27.rawValue;
NumericField28.rawValue = rent / sqft;
}else{
NumericField28.rawValue = "0";
}
}
}


I keep getting an invalid token error so I'm wondering if HasValue is a valid property in javascript or if this is acrobat specific and I have to use the calculate event and if so where is the calculate event for the ZField we'll say. Also, the Z field is just made up and that isn't my actual code it was just an example depicting what I am trying to do.


Justin
ndjustin20
Registered: Oct 7 2009
Posts: 21
Ok I get it................LOL.........I haven't been using the IDE inside acrobat............now that i am using the IDE much much much easier to code. I thought, cause i wasn't thinking, you had to use javascript to do calculations inside the livecycle environment :-)


Thank you for all of your help and patience.

Justin