## Division by Zero error

## Division by Zero error

(OP)

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

TIA

Ben Marthin

## RE: Division by Zero error

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

## RE: Division by Zero error

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

## RE: Division by Zero error

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.

## RE: Division by Zero error

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

LMC

cryerlisa@hotmail.com

## RE: Division by Zero error

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

www.chelseatech.co.nz/pubs.htm

## RE: Division by Zero error

If a Crystal formula encounters a null field value it crashes unless the situation is handled with isnull test