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

Trying to divide numeric field - need HasValue code

NewsShmooze
Registered: Feb 13 2009
Posts: 24
Answered

I've added 5 fields together (G11+G12+G13+G14+G15)and totalled them in
 
G1Total = G11+G12+G13+G14+G15. Then I want to divide the following
 
G1FinalTotal = G1Total / G1NumberofItems
 
But the problem is that FormCalc is trying to divide G1NumberofItems before there is a value entered there. Can someone help me with the HasValue code? I know what I have to do, but don't know how to do it, where to apply it, or what to call it!
 
Thanks

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
What error message are you getting?

I would expect that the HasValue function returns true for non-null, non-blank and non-empty values. I would expect zero is a non-null, non-blank and non-empty value.

I would look at using an 'if' statement to test for a non-zero value and then perform the division for non-zero values.

George Kaiser

NewsShmooze
Registered: Feb 13 2009
Posts: 24
I get the arithmetic under/overflow warning because G1NumberofItems has no value until the user enters it, but the G11, G12, G13, G14, G15 fields are filled in first.

If i could somehow get G1Total to calculate and then after G1NumberofItems is entered by the user G1FinalTotal is calculated, but it all happens simultaneously.

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Accepted Answer
You need to use an 'if' statement to restrict the division to only occur when the item count is not zero.

Calculation script for the 'G1NumberofItems':

Count(G11, G12, G13, G14, G15)

Calculation script for 'G1Total':

G11 + G12 + G13+ G14 + G15

Calculation script for 'G1FinalTotal':

if (G1NumberofItems <> 0) then
G1Total / G1NumberofItems
else
null
endif


George Kaiser

NewsShmooze
Registered: Feb 13 2009
Posts: 24
Much appreciated! Works like a charm!