On Sat, Feb 18, 2012 at 9:57 PM, J. Landman Gay <jac...@hyperactivesw.com> wrote:
> function whichOne var,fld1,fld2 > -- from a handler by Tony Root > -- Handles a case where you need to return one value if your key is empty, > another if not. > > return (item offset(char 1 of (var = empty),"tf") of quote & fld1 &","& > fld2 & quote) > end whichOne > This seems unduly specialized. I use this function: function iff b,t,f --inline if statement if b is true then return t else return f end iff For your particular use case you would call it like this: return iff(var = empty,fld 1,fld 2) One drawback of this function is that all arguments must evaluate without error, so you can't replace something like this: if y = 0 then return x else return x/y with return iff(y = 0,x,x/y) because x/y will fail. Way back when in my crazy days I wrote a macro parser for the script editor, and one of the macros I wrote would take something like the above iff statement and expand it into the other statement so you could use the iff with impunity, but as I said, that was about ten years ago, and it was buggy. gc _______________________________________________ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode