INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

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

RE: Division by Zero error

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

RE: Division by Zero error

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

RE: Division by Zero error

(OP)
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.

RE: Division by Zero error

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 "standard" for me...)

LMC
cryerlisa@hotmail.com

RE: Division by Zero error

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
www.chelseatech.co.nz/pubs.htm

RE: Division by Zero error

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

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close