Re: Differences between VB6 and VB.Net causing problem





"Larry Serflaten" <serflaten@xxxxxxxxxxxxxx> wrote in message news:e1TKh6NMJHA.4772@xxxxxxxxxxxxxxxxxxxxxxx

"Bill McCarthy" <Bill@xxxxxxxxxxxxx> wrote

Oh, and for the record, VB6 and VB.NET do NOT store 0 and -1. For example,
try Dim x as Byte : x = True. Both will give you 255 which is the Not False
value for that data type :)


What do you get when you try to store True to a Decimal type? Are all bits
flipped there? (Oops - not the Not False value there, is it?)


Yeh my bad I should have said all bitwise types. Obviously String, TextBox, Form etc etc, don't have a bitwise state, nor do Decimal, Double, Single or Currency etc. For VB6 the list of bitwise types is reasonably small (bitwise types are the types you can use And, Or and XOr with) : Boolean, Integer, Byte and Long. For VB.NET it includes both the signed and unsigned byte, Itn16, Int32 and Int64 and Boolean.


In VB6, True is a 32 bit value with all bits set.


No it is not. It is 16 bit in Vb6. If you don't beleive the documentation try it yourself:


Private Type Foo
a As Boolean
b As Boolean
c As Boolean
d As Boolean
End Type

Dim x As Foo
Debug.Print LenB(x)

I get 8 bytes, which is 2 bytes (aka 16 bit) per Boolean.




In two's complement form
that is -1. If you try to stuff True into a smaller type, the higher order
bits are truncated. If you try to stuff True into a larger type, that type's
representation of -1 is used.


Nice theory but that isn't what happens. The defualt size in VB6 is 16 bit. I think what they do is a rotating right shift with carry, or jsut use logic expression for the conversion.


IOW:
If the Byte type was a signed type, the &HFF would be -1.


Right, but you are starting with &HFFFF, and that does not give you &HFFFFFFFF for a VB6 long nor does it give you &HFFFFFFFFFFFFFFFF for a VB.NET Int64. There's clearly some intervention at work ;)
















.



Relevant Pages

  • Re: Differences between VB6 and VB.Net causing problem
    ... Converts them both to the same type (Boolean) and does the compare. ... For VB6 the list of bitwise types is reasonably small ...
    (microsoft.public.vb.general.discussion)
  • Re: Sorting a System.Collections.ObjectModel.Collection
    ... Public Sub Dispose() Implements System.IDisposable.Dispose ... Private m_SupportsSorting As Boolean = True ... Protected Overrides ReadOnly Property SupportsSortingCoreAs Boolean ... Dim m_SortList As New ArrayList ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Sorting a System.Collections.ObjectModel.Collection
    ... Public Sub Dispose() Implements System.IDisposable.Dispose ... Private m_SupportsSorting As Boolean = True ... Protected Overrides ReadOnly Property SupportsSortingCoreAs Boolean ... Dim m_SortList As New ArrayList ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Can this be automated in the VBE?
    ... Function DB2SQLite(bNewFile As Boolean, strDB As String, _ ... strTable As String, strSQL As String, _ ... Optional strIndexFields As String, Optional bNoMessage As Boolean, _ ... Dim lRowCount As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: Courtesy Review
    ... Dim pStrConfirm As String ... Dim bValidated As Boolean ... Dim pInvalidStr As String ...
    (microsoft.public.word.vba.general)

Loading