Page 1 of 1

Avoid dividing by zero errors

Posted: Tue Jul 02, 2013 7:54 pm
by PoLyGLoT
Hi all,

Any quick workarounds to tell Livecode that, if the divided value of two numbers is 0, to put "0" or some kind of placeholder into that particular cell?

In the past, I've essentially done a workaround such as:

Code: Select all

if value = 0 then
put "999999999999999" into var
else
put (var1/var2) into var
end if
...but that can get cumbersome if you have lots and lots of values.

Re: Avoid dividing by zero errors

Posted: Tue Jul 02, 2013 9:18 pm
by dunbarx
I don't know of any way to pretest whether or not a divisor is 0 except, well, to pretest whether or not that divisor is 0

Something like:

put yourDividend into dividend
put yourDivisor into divisor

if divisor <> 0 then put dividend / divisor into tResult
else put 0 into tResult.

Craig Newman