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

Calculate 2 fields (multiply) - need value of 0 not to be displayed

KevinT
Registered: Jul 23 2009
Posts: 3
Answered

I'm tying to create an expense report. I want the fields to calculate. But when there are not data I would like the field to be blank instead of "0"

For example. I have a mileage rate in one fied of "0.55" cents a mile. That field should be multiplied by the # of mles driven. When there is mileage, the value should be displayed.

The problem is when there are no miles driven, I would like the field to be blank, instead of "0" (number zero).

I would like to do the same for total fields for the columns too.

I am using Acrobat Pro

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
How are you doing this calculation. If you are using a 'custom calculation script', you can incorporate setting the field to a 'null' value as part of the script.

For all methods of calculations one can use the 'custom validation script' to test the result for zero and set the field's value to the 'null' string.
// test result/ entry for a value of zeroif (event.value == 0) {// zero value  - null the value of the fieldevent.value = '';} // end of if zero

This code does not work if the result is less than the displayed number but greater than zero. This would not be likely for this situation, but it is a possibility in other types of calculations that could also use this technique.

George Kaiser

Steven Wilkes
Registered: Aug 26 2011
Posts: 5
George - I have seen this problem mentioned a few times and I'm still not exactly sure where to reference the code above in a calculation field. I'm currently using LiveCycle Designer 8.2.

It's a simple invoice form using FormCalc for the calculations. I'm not a developer so I'm not keen on getting into Java...

It's strange that the first calculation (one field multiplied by another from a table) i.e. dayrate * quantity does not show any zero value when the form is empty. Once these are added, it populates a field called pretax with the answer.

Some line items are subject to UK sales tax (VAT) and others are not. I am trying to keep the form simple so I then have a field called VATRate which I can either put the going rate in as 20% or 0% as appropriate.

The VATAmount calculation result field is next and is calculated as (PreTax * VATRate) * 0.01. It seems that by adding in a number to multiply or divide the calculation by always then forces the field to have a £0.00 entry in it which looks really silly in the form as there are 20 line items in the table.

My final column is for a total and this always then shows a value of £0.00 and it's driving me nuts trying to get rid of it. The calculation for the final column is a simple sum of Sum (PreTax, VATAmount).

I've seen you reply to similar posts in the past which I've read but it's not at all clear to me how and where to use the custom validation script. I would live a simple line by line desription of how and where to psecify the script so that the two columns will start behaving.

Many thanks...

Steven

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
I would use the percentage format for the decimal field, "z9.99%"

Under exactly what circumstances do you want the zero value to display?

All the time?
No Script needed.

If any of the fields have a value?

DecimalField1 * DecimalField2
if($.rawValue == 0) then
null
endif

Only if both feilds have a value?

if(HasValue(DecimalFeild1) & HasValue(DecimalField2) ) then
DecimalField1 * DecimalField2
if($.rawValue == 0) then
null
endif
else
null
endif

George Kaiser

Steven Wilkes
Registered: Aug 26 2011
Posts: 5
George - thanks for the quick reply. Ideally, I'd just just like to do a free entry for the VAT rate so that I can either put the current rate of 20 in the box if the line item is subject to VAT or 0 if the item is not subject to VAT.

It seems like it should be such a trivial thing to fix but I cannot see where to reference the script - where do you add it? In the script editor pane or is it done as an entry on the validation pattern dialogue box?

Currently, using your string above, I have the following as the calculation for the field: -

(PreTax * VATRate) * 0.01 // test result/ entry for a value of zeroif (event.value == 0) {// zero value - null the value of the fieldevent.value = '';} // end of if zero

I've tried it before, after the calculation and although if I click check script syntax (seems fine) the zeros are still there.

I have researched this all over the web for many hours and cannot find a simple answer of what to do, where etc.

Regards...Steven
Steven Wilkes
Registered: Aug 26 2011
Posts: 5
Sorry George - did you edit you post? by the time I replied, it looks like your answer had changed.

Basically, I want all the fields to appear empty until I start filling them in in this order: -

NumDays, DayRate, PreTax(Calculated/read only from first 2), VATRate (I want to enter 20 or 0 and am using num{zzzz9.zzz'%'} as the format), VATAmount (Calculated/read only using the calculation I posted earlier) and the last field is a sum of PreTax and VATAmount (Calculated/read only).

Steven....
Steven Wilkes
Registered: Aug 26 2011
Posts: 5
George - Thanks for the last post. Using your script, it DOES clear the £0.00 entries from VATAmount and my LineTotal columns which is exactly what I want so thanks...

BUT, using: -

if(HasValue(PreTax)) then
(PreTax * VATRate) * 0.01
if($.rawValue == 0) then
null
endif
else
null
endif

as the calculation, it no longer calculates the amount of sales tax when I put in 20 as the VATRate....It comes out as £0.00.

I may be being very dim but I can't see why.

Many thanks for your help...
Steven Wilkes
Registered: Aug 26 2011
Posts: 5
George - I wondered if you had had any thoughts re my last post? Using the script I quoted, it fails to calulate the amount of VAT.

I've tried a couple of other methods too like: -

if (PreTax > 0) then
$.presence = "visible";
(PreTax * VATRate * 0.01);
else
$.presence = "invisible";
0;
endif

Which is fine but it removes the borders from the then hidden fields in the table and makes it look odd as there's 8 body rows in my table. Is there a function instead of $.presence I can use instead that would hide the calculated contents rather that the whole field?

Thanks, Steven


gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
"invisible" hides the entire form field, and entire includes the borders.

null should work if your form is set up to allow this and the calculations are done in the correct order.

First I would make very sure that your form is working properly. No error messages when opening preview, or in the JavaScript console as the form is completed, the fields are calculating correctly and as expected. Then you can go back and fix the appearance of the form.

You may want to check that your "PreTax" does not have a very small value that displays as zero but is greater than zero.




George Kaiser