L ALVEY <trukker <at> btinternet.com> writes:

> 
> I used a similar method in an earlier version of the screen which worked 
fine. In my form, I used the MOD()
> function which catches the error, as does the % operator. There is some 
inconsistency here in that % traps
> the error but / doesn't.
>  
> Thanks to everyone who contributed.
> 
> ________________________________
> From: Man-wai Chang <changmw <at> gmail.com>
> To: ProFox Email List <profox <at> leafe.com> 
> Sent: Monday, 12 August 2013, 15:27
> Subject: Re: FP: Trapping division by zero (Error 1307)
> 
> This is my Foxpro/DOS way of catching division by zero:
> 
> on error *
> x=1/0
> if if "*"$x
>     ? x
>     ? "divide by zero"
> endif
> on error
> 

if num is the numerator and den is the denominator then you can just use the 
expression:
IIF(den=0,0,num/den)

This returns 0 if the denominator is zero (or you can set it to anything you 
wish.  Works well within a SQL statement or in a normal expression.




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to