Re: Differences between VB6 and VB.Net causing problem
- From: "Bill McCarthy" <Bill@xxxxxxxxxxxxx>
- Date: Mon, 20 Oct 2008 16:17:04 +1100
Hi Robert,
I think we agree on most of this, especially the important part of Booleans, hence True and False being 16 bit.
Just some minor corrections and statements inline:
"Robert Morley" <rmorley@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:%23tcK0umMJHA.4676@xxxxxxxxxxxxxxxxxxxxxxx
Okay, I'm royally confused at this point. See inline:
Larry Serflaten wrote:What do you think the If bln = CByte(255) Then does ?Converts them both to the same type (Boolean) and does the compare.
CByte won't convert anything to boolean, it'll convert it to byte. Did you perhaps mean to use CBool?
Wrong. Did you try :
If bln = CByte(254) Then
We must not be observing the same results. The above test backs up
my statement, it does not refute it. I said the CByte(X) is evaluated to
a boolean and then the rest of the comparison is done. In the case of
255, CByte converts to True so the statement is True, and for 254
CByte converts to false so the statement is false.
Here again, CByte converts 255 to 255 and 254 to 254, not True or False, oddly enough. :) CBool would convert BOTH, and any other non-zero value, to True, not False.
Thankyou ! That is of coruse the fundamental of what Booelan is, zero or non zero.
If you did you would know your above statement is incorrect.
You don't see it the same as I.... I have to wonder if you even look.
Unless I'm missing out on something, I think you BOTH need to re-look!
Huh ? I was pointign you to Larry his assumption that the Byte was beign converted to a Booelan in the expression If bln = CByte(255) Then was clearly wrong. It is the Boolean that gets converted to a Byte. That's why I showed him if the valeu is 254 instead of 255 it's no longer equal, becuase it equates to If 254 = 255 Then. Larry on the other hand beleives it is If True = False Then which is fundamentally wrong.
Where do you get that? I'd say it converts the byte to a boolean.
See above. You are wrong. A very simple test can confirm this.
That test above proved my point, either you see a different result,
or you don't understand what you are seeing....
Other than the original CDec(True) statement, there were no Booleans involved in any of the remaining code that I saw...only Bytes and Decimals. This is why I'm confused. Was there something in Bill's posts (which I'm not seeing) that used Booleans?
To be clear I never introduced the CDec thing, that was Larry. He claimed you could do bitwise operations on them. In fact he claimed you could also do them on Strings !! I tried pointing you to him that it was a conversion to a Long that was taking place before the call to Hex, but he wouldn't listen to me.
Similarly, the assertion that True is all bitwise 1's in whatever numeric format is also incorrect. CSng(True) is 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.
No. Single and Double and Decimal and in fact Currency are not bittable numeric types. I said this to Larry early on. 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.
Likewise, String is handled differently.
Any way, again I'm done with arguing with you on this. There is absolutely
no doubt you are wrong. There should also be no doubt that a Boolean is 16
bytes in VB6.
16 bytes?!? I think Bill must've meant 16 bits, and that much is easily proven with:
Dim bln As Boolean
Debug.Print Len(bln)
Yes I did mean 16 bits not bytes. I had said this multiple times previously to Larry and showed him a UDT with four Booleans so as he could look at the in memory structure, and that also proved it was 16 bytes per Boolean.
So anyway, what was the point of this debate? I really wasn't following it all, but the various erroneous statements made by both sides made what little I did read extremely hard to follow in any event.
If I understood correctly, the debate was whether or not True is represented as a 32-bit value, and I'm not sure it inherently HAS a number of bits. If it does, I would guess that it's a standard 16-bit Boolean value, converted to other formats based on VB6's design (in most normal cases where integer types are being used, this would mean it's truncated, converted directly, or sign-extended as appropriate). The assertion that it's 32 bits because Hex(CDec(True)) returns FFFFFFFF is erroneous, as Hex's limit is 32 bits, so the Decimal is being converted back down to a Long before Hex spits out its answer. You can easily prove this by trying:
Debug.Print Hex(CDec(2147483647))
Debug.Print Hex(CDec(2147483648))
The second one will, of course, generate an overflow.
Any questions or comments? Or am I wandering off on the wrong path?
Thanks Robert that was exactly what I was saying to Larry.
A boolean is 16 bytes.
True and False are also 16 byte by nature. You could check a Variant and it would show it is by default a VT_BOOL.
Any non zero value when converted to a Boolean is True.
A Boolean converted to a bitable numeric type (Long, Integer and Byte in VB6) has the value of 0 or bitwise Not 0.
For all other numeric conversions, the value of default type of an integer is used, giving -1. (also 16 bit)
And for conversions from string the string value has to be case insensitive"true" or "false" or anything that can be converted to a numeric, where the 0 or non zero rule applies.
.
- 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
- 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
- Re: Differences between VB6 and VB.Net causing problem
- From: Larry Serflaten
- Re: Differences between VB6 and VB.Net causing problem
- From: Robert Morley
- Differences between VB6 and VB.Net causing problem
- Prev by Date: Re: Differences between VB6 and VB.Net causing problem
- Next by Date: LargeHex function revisited
- 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):
Relevant Pages
|