Re: Differences between VB6 and VB.Net causing problem
- From: "Larry Serflaten" <serflaten@xxxxxxxxxxxxxx>
- Date: Sat, 18 Oct 2008 14:10:23 -0500
"Bill McCarthy" <Bill@xxxxxxxxxxxxx> wrote
"The True keyword has a value equal to -1."
So how is it you say VB6 does not store -1 for True? What do
they store???
They store all bits set in a Boolean type that occupies 16 bytes. When
converted to VB6's natural type for numerics, Integer, that's -1.
<... snipped code ...>
What you are seeing is the converion. Now try the above with -1 instead of
bln, and I can assure you that -1 <> CByte(255)
That is not surprising, you are comparing apples to oranges.
-1 is an Integer and CByte(255) is a Byte, of course -1 <> 255
Put them both in the same type, then compare:
Dim bln
bln = CDec(True)
If bln = CDec(-1) Then
Debug.Print "it is -1"
End If
If bln = CDec(CByte(255)) Then
Debug.Print "it is 255"
Else
Debug.Print "it is " & Hex(bln)
End If
Here CByte(255) does not evaluate to True, for obvious reasons. Also
note that True is represented as FFFFFFFF, a 32 bit value even when
the Decimal type can hold more than 32 bits of information. (On a side
note, its not 'all bits set' in the variable's memory...)
I would propose that since a Byte type cannot represent negative numbers
the VB designers used 255 rather than raising an error. It may very well
be a one-off situation they did to add 'ease of use', rather than raise the
overflow error which you'd normally see when trying to stuff -1 into a Byte.
LFS
.
- Follow-Ups:
- Re: Differences between VB6 and VB.Net causing problem
- From: Bill McCarthy
- Re: Differences between VB6 and VB.Net causing problem
- From: Kevin Provance
- Re: Differences between VB6 and VB.Net causing problem
- References:
- Differences between VB6 and VB.Net causing problem
- From: Howard G
- Re: Differences between VB6 and VB.Net causing problem
- From: Tom Shelton
- Re: Differences between VB6 and VB.Net causing problem
- From: expvb
- Re: Differences between VB6 and VB.Net causing problem
- From: Tom Shelton
- Re: Differences between VB6 and VB.Net causing problem
- From: Bill McCarthy
- Re: Differences between VB6 and VB.Net causing problem
- From: Larry Serflaten
- Re: Differences between VB6 and VB.Net causing problem
- From: Bill McCarthy
- Re: Differences between VB6 and VB.Net causing problem
- From: Larry Serflaten
- Re: Differences between VB6 and VB.Net causing problem
- From: Bill McCarthy
- Differences between VB6 and VB.Net causing problem
- Prev by Date: Re: Differences between VB6 and VB.Net causing problem
- Next by Date: Re: Extended File properties
- Previous by thread: Re: Differences between VB6 and VB.Net causing problem
- Next by thread: Re: Differences between VB6 and VB.Net causing problem
- Index(es):
Loading