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

Auto Correct Decimal Field from 0/Null to 1

rclarke
Registered: Nov 20 2009
Posts: 11

Hi,

I'm sure there is a very simple explanation on how to achieve the following, however after several hours of Googling I am still at a loss!

I have a form which allows the user to enter an exchange rate which is then used by other fields in calculate events. The issue is that I need to trap and correct null and zero values before they can be used by the other fields otherwise I will get a division by zero error. All I want to do is change a null or zero to a one and then notify the user of their error. I have tried to implement this change in the validate event of the exchange rate field, but all I receive is a "Value Validate Failed" error message. I am keen to trap this issue at source rather than insert checking code in all the calculate events.

Thanks,

Rod.

My Product Information:
LiveCycle Designer, Windows
jonom
Registered: Jan 31 2008
Posts: 133
I think this should work (formcalc)
if ($ == null or $ == 0) then$ = 1endif

I've done something similar before but put the code on the fields doing the calculating.

if (Field1 == null or Field2 == null) then$ = nullelse$ = (Field1 / Field2)endif
rclarke
Registered: Nov 20 2009
Posts: 11
Thanks jonom. I have tried putting similar code in the Validate and Exit event of the offending field but it appears that Calculate events fire before them so I still get the division by zero error before the script can change the value from zero or null. At the moment I am handling this by putting checking code in each and every Calculate event (of which there are many), but it just seems such a poor way of handling the problem. My hope is that there is an event that fires before Calculate when the field value changes so that I can fix it at source, rather than destination :-7

Thanks,

Rod.
jonom
Registered: Jan 31 2008
Posts: 133
Ya, Validate wouldn't work but I thought Exit would.

Just found this in the help for the Exit event:
[i]Note: If the purpose of your script is to manipulate the value of the current field, you need to consider attaching your script to the calculate event.[/i]

So give Calculate a try!
rclarke
Registered: Nov 20 2009
Posts: 11
That sounded like a really good idea, so I just tried that with the field Object -> Value -> Type set as "User Entered" and then "Calculated - User Can Override", but I'm sorry to say it didn't work with either setting. My Formcalc code was:
if ($.rawValue == 0) then$.rawValue = 1xfa.host.messageBox("Rate values cannot be zero! Rate 1 has been changed to a value of 1.0000", "Invalid Rate", 1, 0)endif

Amazing how something SO simple is apparently SO difficult :/

Thanks anyway,

Rod.
jonom
Registered: Jan 31 2008
Posts: 133
Hopefully someone else can help - I'm afraid I don't have time to build a sample and test right now.

I'm sure there's a way to do it.
rclarke
Registered: Nov 20 2009
Posts: 11
No problem ... I appreciate the input :)

As you said, hopefully someone else must have tried and solved this seemingly basic issue.

Rod.