Microsoft VB Bug

Replies:

  • None.

Parents:

  • None.
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01BFE2C7.0AEFD480
Content-Type: text/plain;
charset="iso-8859-1"

Since we are dissing Microsoft today and I am not getting much done at work,
I'll make one more contribution. This absolutely KILLS me. I discovered it
last week while debugging some VB code I wrote.

In VB there is a Boolean data type which is either TRUE (which evaluates to
an integer "-1") or FALSE (integer "0"). Coming from a C/C++ background, it
is not uncommon to do something like:
if (condition) then ....
where condition is an expression that is not a Boolean data type but which
is implicitly cast to one. For example, in C/C++ where the condition is an
integer expression, "0" evaluates to a boolean FALSE and anything > 0 is
TRUE. This is the situation I was programming with in VB and I wasn't sure
if it was treated the same so in the debug window I did a little test:
   > if 16 (or any > 0 integer) then print "Hello"
VB printed "Hello"
   > if 0 then print "Hello"
VB didn't print anything.

Works like C/C++ I thought, and off I went. Two weeks later a found a bug in
my bitmap parsing code that used the code I describe above. It turns out
that if the condition in the "if" statement is integer you have to use "-1"
for TRUE and "0" for FALSE --  nothing else!!!  That would be fine (just
restrictive) but look what VB does when you have an integer > 0:

> Dim iTemp As Integer
> iTemp = 16
>
> if iTemp then print "Hello"    -- VB prints "Hello"
>
> if NOT iTemp then print "Hello"  -- VB also prints "Hello" !!!!!

This defies all logic (and not to mention caused a bug in my code).
Apparently there is no Boolean translation for integers > 0 and instead of
issuing an error or doing something sensible, that expression evaluates to
TRUE AND also to FALSE. Yikes!  I can't believe that that exists in the 6th
edition of VB.


------_=_NextPart_001_01BFE2C7.0AEFD480
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2232.0">
<TITLE>Microsoft VB Bug</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2 FACE=3D"Arial">Since we are dissing Microsoft today =
and I am not getting much done at work, I'll make one more =
contribution. This absolutely KILLS me. I discovered it last week while =
debugging some VB code I wrote.</FONT></P>

<P><FONT SIZE=3D2 FACE=3D"Arial">In VB there is a Boolean data type =
which is either TRUE (which evaluates to an integer &quot;-1&quot;) or =
FALSE (integer &quot;0&quot;). Coming from a C/C++ background, it is =
not uncommon to do something like:</FONT></P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Arial">if (condition) then ....</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">where condition is an expression that =
is not a Boolean data type but which is implicitly cast to one. For =
example, in C/C++ where the condition is an integer expression, =
&quot;0&quot; evaluates to a boolean FALSE and anything &gt; 0 is TRUE. =
This is the situation I was programming with in VB and I wasn't sure if =
it was treated the same so in the debug window I did a little =
test:</FONT></P>

<P><FONT SIZE=3D2 FACE=3D"Arial">&nbsp;&nbsp;&nbsp; &gt; if 16 (or any =
&gt; 0 integer) then print &quot;Hello&quot;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">VB printed &quot;Hello&quot;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">&nbsp;&nbsp;&nbsp; &gt; if 0 then =
print &quot;Hello&quot;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">VB didn't print anything.</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">Works like C/C++ I thought, and off I =
went. Two weeks later a found a bug in my bitmap parsing code that used =
the code I describe above. It turns out that if the condition in the =
&quot;if&quot; statement is integer you have to use &quot;-1&quot; for =
TRUE and &quot;0&quot; for FALSE --&nbsp; nothing else!!!&nbsp; That =
would be fine (just restrictive) but look what VB does when you have an =
integer &gt; 0:</FONT></P>

<P><FONT SIZE=3D2 FACE=3D"Arial">&gt; Dim iTemp As Integer</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">&gt; iTemp =3D 16</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">&gt; if iTemp then print =
&quot;Hello&quot;&nbsp;&nbsp;&nbsp; -- VB prints =
&quot;Hello&quot;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">&gt; if NOT iTemp then print =
&quot;Hello&quot;&nbsp; -- VB also prints &quot;Hello&quot; =
!!!!!</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">This defies all logic (and not to =
mention caused a bug in my code). Apparently there is no Boolean =
translation for integers &gt; 0 and instead of issuing an error or =
doing something sensible, that expression evaluates to TRUE AND also to =
FALSE. Yikes!&nbsp; I can't believe that that exists in the 6th edition =
of VB.</FONT></P>

</BODY>
</HTML>
------_=_NextPart_001_01BFE2C7.0AEFD480--

HURL: fogo mailing list archives, maintained by Gerald Oskoboiny