realbasic-nug
[Top] [All Lists]

Nice little variant compare gotcha

To: realbasic-nug at lists dot realsoftware dot com
Subject: Nice little variant compare gotcha
From: Robert Woodhead <trebor at animeigo dot com>
Date: Thu, 30 Dec 2004 17:56:01 -0500
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <20041230213934 dot 081C36284FD at lists dot realsoftware dot com>
Dim v as Variant

v = 0.5

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

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

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

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

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.

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.

--

===========================================================
Robert Woodhead, CEO, AnimEigo     http://www.animeigo.com/
===========================================================
http://selfpromotion.com/   The Net's only URL registration
SHARESERVICE.  A power tool for power webmasters.
_______________________________________________
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>