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

Zero and Null in Calculations

HLF
Registered: Jan 6 2008
Posts: 21
Answered

With formCalc, I do

sum(field1,field2,field3)

When the sum is zero I would like to display null rather than zero.

I am not at all particular about the language for the approach. I will use either formCalc or javascript.

An approach to this problem using Acrobat Forms rather than LifeCycle Designer would be useful as well.

Thank you.

Howard

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You can try

if (sum(field1,field2,field3) eq 0) ""
else
sum(field1,field2,field3)
endif

This sets the field value to "" when zero. Another approach would be to hide the field.

George Kaiser

HLF
Registered: Jan 6 2008
Posts: 21
Thank you George.

I have

if (sum(field1,field2) eq 0) ""
else
sum(field1,field2)
endif

as you suggested but I receive the following alert:

Error: syntax error near token "" on line 1 column 31.

Have I missed something or copied something incorrectly?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
That might not work in FormCalc, I do not have an available copy right now. It does work in Acorbat forms. You could also allow the field to display zero and make the presence "invisible"

sum(field1,field2)
if ($.rawValue eq 0)
$.presence = "invisible"
else
$.presence = "visible"
endif

A search turned up:

http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=6563

George Kaiser

HLF
Registered: Jan 6 2008
Posts: 21
I very much appreciate your help.

Actually I prefer using Acrobat Forms to LifeCycle.

I tried the script

if (sum(field1,field2) eq 0) ""
else
sum(field1,field2)
endif

In Acrobat and received the error message

Missing ) after condition 1: at line 2

Getting closer!
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Acrobat JavaScript's syntax is different, but the "null" vaue may still need to be used and since you have only 3 fields to sum:

// JavaScript in the Calculation event
// Sum of fields
this.rawValue = Field3.rawValue + Field2.rawValue + Field1.rawValue;
if(this.rawValue == 0)
this.rawValue = null;

George Kaiser

HLF
Registered: Jan 6 2008
Posts: 21
This script works perfectly in LifeCycle Designer.

Many thanks for your persistence.

Howard