Re: Differences between VB6 and VB.Net causing problem




"Bill McCarthy" <Bill@xxxxxxxxxxxxx> wrote
You are saying -1 doens't equal 255; yet True does

Didn't you see, 255 does not equal True. The value of True is -1.
A Byte value cannot represent a negative number.

What do you think the If bln = CByte(255) Then does ?

Converts them both to the same type (Boolean) and does the compare.
As I said, they may have made the decision to allow a conversion between
Byte and Boolean. In that case the byte value 255 is the only logical choice
in keeping with the rest of the language. When you force them to be in
identical types, 255 will not equal -1.

Seriosuly I am curious as to why you think that is "appels to oranges" when the rules
for the comparison dictate that the boolean is converted to a byte.

Where do you get that? I'd say it converts the byte to a boolean.
In case you forgot, the If <condition> has to evaluate to a boolean and
one of the operands is already a boolean type. So that one-off conversion
converts CByte(255) to a Boolean value of True and the comparison continues.


How many times do I have to tell you Decimal, Single and Double are not
bitwise types ?

No. It's actually to do with **bitwise** operations.


What makes Integer and Long bitwise types? The fact that they work
in logical/bitwise operations? So does Decimal....

v1 = CDec(&HFA)
v2 = CDec(&HAF)
Debug.Print Hex(v1 And v2)

Here's an interesting exercise:

? Hex(Not CByte(0))
? Hex(Not CBool(0))
? Hex(Not CInt(0))
? Hex(Not CDate(0))
? Hex(Not CLng(0))
? Hex(Not CSng(0))
? Hex(Not CDbl(0))
? Hex(Not CCur(0))
? Hex(Not CDec(0))
? Hex(Not CStr(0)) ' <<< It can pick any data size it wants, yet 32 bits is shown.

It sure appears to me that given the space to do so, True represents
a 32 bit number whose value is -1.

LFS







.



Relevant Pages

  • Re: Differences between VB6 and VB.Net causing problem
    ... Converts them both to the same type (Boolean) and does the compare. ... In that case the byte value 255 is the only logical choice ... So that one-off conversion ... What makes Integer and Long bitwise types? ...
    (microsoft.public.vb.general.discussion)
  • Re: returning values from multiselect list as string
    ... > calculation, including boolean arithmetic. ... The conversion of *both* ... The most common boolean expressions used in If-Then statements use the ... and some languages give assignment and comparison ...
    (microsoft.public.word.vba.beginners)
  • FormView checkbox two-way bind problem with null fields
    ... In the source these fields my be empty. ... Conversion from type 'DBNull' to type 'Boolean' is not valid. ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Differences between VB6 and VB.Net causing problem
    ... Converts them both to the same type (Boolean) and does the compare. ... I was pointign you to Larry his assumption that the Byte was beign converted to a Booelan in the expression If bln = CByteThen was clearly wrong. ... CSngis a perfectly valid conversion, albeit a highly unlikely one, and it will indeed return -1, but it certainly doesn't return all bitwise 1's when examined at the bit level. ... It is only in the bittable numeric types where bitwise operations can be used, and in those types the conversion of a Boolean is either 0 or bitwise Not 0. ...
    (microsoft.public.vb.general.discussion)
  • Re: Differences between VB6 and VB.Net causing problem
    ... For VB6 the list of bitwise types is reasonably small: Boolean, Integer, Byte and Long. ... Dim x As Foo ...
    (microsoft.public.vb.general.discussion)