Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Division by Zero error

Status
Not open for further replies.

Bennie47250

Programmer
Nov 8, 2001
515
US
I have some reports that occasionally will error out with a Division by Zero error message. I understand what causes this error and how to resolve after I receive the error but I’m wondering it there is a better way. I may design my report in June of a year and at that time all the formulas have data in them so they don’t get this error. However if the report is ran in January of a new year, some formulas may have no data and the error is received. Looking for suggestions on how to program around this type of error.

TIA
Ben Marthin
 
How do you handle it currently??

standard way is

numbervar x;
if not isnull({table.value}) then
x := {table.othervalue} / {table.value}
else
x := 0; // or whatever you want the value to be
 
how about this:

If isNull({field}) or if {field}=0 then 0
else <<value or expression>>/{field}

This will avoid /0 problems, Null fields included. Software Support for Sage Mas90, Macola, Crystal Reports, Goldmine and MS Office
 
Typically I will write the formula as: myfield1/myfield2.

When I have the division by 0 error rear its ugly head, I will change the formula to:
if myfield1 = 0 then 0
else if myfield2 = 0 then 0
else myfield1/myfield2
This usually resolves the problem. I was hoping there was a better way. Looks like there isn’t so I will just try to remember to always put in the first two lines in each time I do a formula with a division.

Thanks for everyone’s help.
 
if you program it right using the examples given above you should never have to go back and fix this again - predict the problem BEFORE it happens and let the report handle it for you.

I like DGILLZ formula - that is what I use (and I work with financial reports so this is a &quot;standard&quot; for me...)

LMC
cryerlisa@hotmail.com
 
Whenever I do a division formula I always use
if {table.field1}=0 then 0 else
{table.field2}/{table.field1}

1) Do this every time you write a formula and divide by zero errors won't appear
2) NULL's don't cause a problem because the result of dividin by NULL is NULL - so not a problem
3) You don't need to test {table.field2} as 0 divided by anything is still 0.

If you don't do the above, one day a divide by zero will ocurr and stop your report in it's tracks.
Editor and Publisher of Crystal Clear
 
A NULL value IS a problem

If a Crystal formula encounters a null field value it crashes unless the situation is handled with isnull test
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top