Hi,
kendall anderson wrote:
> I seem to remember this topic from a long time ago but can't find
> anything in the archives (lingo-l or direct-l), and of course, not
> knowing the name of what I'm looking for doesn't help. :)
>
> What I remember was an 'if/then/else' approach which could be used in a
> single line of code, and I can't remember whether it was usable in lingo
> or only other ('real') languages. An example might be:
>
> For example: pretend we want to return a percentage, and we have a score
> and the total. If the total is 0, we want to avoid a divide by zero so
> we might do the following:
>
> return (total=0: 0) ? (a>0: score/total)
>
> ie: return the percentage if total is > 0, or just return 0 if total =
> 0.
You might use a single line expression like this one:
return (score / (total * (total > 0) + (total = 0))) - score * (total = 0)
-- Welcome to Director --
score = 2.0
total = 10.0
put (score / (total * (total > 0) + (total = 0))) - score * (total = 0)
-- 0.2000
score = 2.0
total = 0.0
put (score / (total * (total > 0) + (total = 0))) - score * (total = 0)
-- 0.0000
But I guess it'd work faster by two lines:
gtz = total > 0
put (score / (total * gtz + not gtz)) - score * not gtz
I find such use of expressions a little exasperated though.
It would be better writing a global handler to mimic the VBasic's
inline if (iif(...)).
on iif (c, e1, e2)
if c the return e1
else return e2
end
So you would simply have:
return score / iif(total, total, 0)
(This one: return iif(total, score/total, 0) would fail because
score/total is ever evaluated, so a divide by zero error occurs)
HTH,
Franco
IFC Programming Consultant
http://www.chnexus.com/main.htm
Private mailto:[EMAIL PROTECTED] | [EMAIL PROTECTED]
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]