Avoid dividing by zero errors

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Avoid dividing by zero errors

Post by PoLyGLoT » Tue Jul 02, 2013 7:54 pm

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.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10356
Joined: Wed May 06, 2009 2:28 pm

Re: Avoid dividing by zero errors

Post by dunbarx » Tue Jul 02, 2013 9:18 pm

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

Post Reply