[Gambas-user] iif bug?

Benoit Minisini benoit.minisini at ...2...
Thu Apr 27 10:32:08 CEST 2006


On Thursday 27 April 2006 01:23, Oliver Etchebarne Bejarano wrote:
> Hey folks,
>
> I'm trying this:
>
> ------
>
> dim id as integer
> dim text as string
>
> text = "1"
> id = iif(IsNull(Val(text)), 0, Val(text))
>
> ------
>
> Obviously, I want to obtain the numeric value of "text", or 0 if it is
> not a valid number. But that code fails with
>
> ERROR: Type mismatch: wanted Integer, got Null instead.
>
> It looks like Gambas is evaluating both true and false parts before
> doing the iif check, and I think that shouldn't be the correct behavior.
>
> btw I'm trying this on gambas 1.9.29
>
> HTH


IIf() is a function, and so evaluates all its arguments. But, moreover, the 
datatype of its two last arguments must be the same, because the interpreter 
code optimizer requires that internal functions return always the same 
datatype.

Actually, I could force Iif() to return a Variant, but I didn't want :-)

Regards,

-- 
Benoit Minisini





More information about the User mailing list