realbasic-nug
[Top] [All Lists]

Re: Nice little variant compare gotcha

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Nice little variant compare gotcha
From: Aaron Ballman <aaron at realsoftware dot com>
Date: Thu, 30 Dec 2004 17:09:07 -0600
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <20041230213934 dot 081C36284FD at lists dot realsoftware dot com> <p061104afbdfa346f1218 at [192 dot 168 dot 1 dot 2]>
v = 0.5

if (v > 0) then
   msgBox "This will not be displayed"
end if

Makes sense to me -- you're comparing to an integer, so the variant assumes an integer.

if (v.doubleValue > 0) then
   msgBox "This will be displayed"
end if

Again, makes sense because you're being explicit.

if (0 < v) then
   msgBox "This will not be displayed either"
end if

Same as above.

if (v > 0.0) then
   msgBox "But this will be"
end if

Same as above.

Whups. The compare should be converting the parameters to the most precise type. Instead, if one of them is a variant, it is converting the variant to the same type as the other parameter.

No, they are converting to the type you are comparing to, which is intended beavior.

Looking very carefully at the documentation, I find this is mentioned in passing at the very bottom of the variant explanation. However, a landmine like this needs to be redflagged with a big "Danger Will Robinson!" message and an example of what not to do.

It's a sensible behavior, but you're right, it could be documented a little clearer.

~Aaron
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>