Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: division by zero Post Reply Post New Topic
Author Message
taniarto
Groupie
Groupie
Avatar

Joined: 15 Oct 2010
Online Status: Offline
Posts: 52
Quote taniarto Replybullet Topic: division by zero
     Posted: 30 Jan 2013 at 2:37pm
I Create a report with some formula such like this :
({OPI_HEAD.QTY_PESAN}/{OPIM_Det1.ISI})/500

from the report display there's no error message. But when the report were exported into excel or another there's an error " division by zero "

please any one tell me to solve it out..

thanks,


Yokanan
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 31 Jan 2013 at 4:27am
if {OPIM_Det1.ISI}=0 then 0 else
({OPI_HEAD.QTY_PESAN}/{OPIM_Det1.ISI})/500
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 31 Jan 2013 at 4:58am
I would make one minor change.  If there's a possiblity that {OPIM_Det1.ISI} will be null, you'll need to use this formula:
 
If IsNull(OPIM_Det1.ISI}) or {OPIM_Det1.ISI}=0 then 0 else
({OPI_HEAD.QTY_PESAN}/{OPIM_Det1.ISI})/500
 
-Dell
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 31 Jan 2013 at 6:09am

Thanks Hilfy, I did not consider the null issue.

However, I believe (just for clarification) that if that field were null it would not error due to division by zero but rather stop evaluating on the null and therefore return a null.
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 31 Jan 2013 at 7:08am
Unfortunately, that's not the case.  I'm not entirely sure that it's a division by 0 error, but it does cause an error instead of just returning null.
 
-Dell
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 31 Jan 2013 at 7:15am
odd, my rudimentary test of dividing by a null numeric field did not give me a null return. 
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 31 Jan 2013 at 9:44am
I'm pretty sure I've gotten this error from nulls....but I don't remember the exact circumstances or version of Crystal.
 
-Dell
IP IP Logged
taniarto
Groupie
Groupie
Avatar

Joined: 15 Oct 2010
Online Status: Offline
Posts: 52
Quote taniarto Replybullet Posted: 31 Jan 2013 at 4:59pm
thanks..all it's working...
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum