Home All Groups Group Topic Archive Search About

This is a Bug, but whose? VB.Net or Mine?

Author
23 May 2009 8:49 PM
Jim Parsells
Using VS2008 targeted at Framework 2.0 on XP SP3 (32 bit)

Given the following Enums:
    <Flags()> _
    Public Enum EMethod As UInteger
        Buffered = 0
        InDirect = 1
        OutDirect = 2
        Neither = 3
    End Enum

    <Flags()> _
    Public Enum EFileDevice As UInteger
        Beep = &H1
        CDRom = &H2
        CDRomFileSytem = &H3
        Controller = &H4
        Datalink = &H5
        Dfs = &H6
        Disk = &H7
        DiskFileSystem = &H8
        FileSystem = &H9
           .
           .      (more --removed for clarity)
           .
     End Enum

I declare another Enum:

    Public Enum EIOControlCode As UInteger
           .
           .
        FsctlSetCompression = (EFileDevice.FileSystem << 16) Or (16 << 2) Or
EMethod.Buffered Or ((FileAccess.Read Or FileAccess.Write) << 14)
             .
             .
    End Enum

Elsewhere, I declare two variables:

Dim X As EIOControlCode = EIOControlCode.FsctlSetCompression
Dim Y as UInteger
  Y=(EFileDevice.FileSystem << 16) Or (16 << 2) Or EMethod.Buffered Or
((FileAccess.Read Or FileAccess.Write) << 14)

and observe that variable X has the hex value of 639040     (wrong)
and that variable Y has the hex value of 9C040  (correct)

Note that the code setting Y is exactly the same as the code setting the
Enum element.

Same code, different results. The only difference is that the Wrong results
are a product of VB.Net's evaluation of the code in the Enum at compile time
whereas the correct results are produced at run time.

The problem, of course is that the EIOControlCode Enum runs to over 100
entries which I now have to consider suspect at best.

Any help will be appreciated.
--
Jim Parsells

Author
23 May 2009 9:07 PM
Family Tree Mike
Show quote Hide quote
"Jim Parsells" <JimParse***@discussions.microsoft.com> wrote in message
news:1EE38E4A-EB4B-48F3-95A9-A3B5BF88D2DE@microsoft.com...
> Using VS2008 targeted at Framework 2.0 on XP SP3 (32 bit)
>
> Given the following Enums:
>    <Flags()> _
>    Public Enum EMethod As UInteger
>        Buffered = 0
>        InDirect = 1
>        OutDirect = 2
>        Neither = 3
>    End Enum
>
>    <Flags()> _
>    Public Enum EFileDevice As UInteger
>        Beep = &H1
>        CDRom = &H2
>        CDRomFileSytem = &H3
>        Controller = &H4
>        Datalink = &H5
>        Dfs = &H6
>        Disk = &H7
>        DiskFileSystem = &H8
>        FileSystem = &H9
>           .
>           .      (more --removed for clarity)
>           .
>     End Enum
>
> I declare another Enum:
>
>    Public Enum EIOControlCode As UInteger
>           .
>           .
>        FsctlSetCompression = (EFileDevice.FileSystem << 16) Or (16 << 2)
> Or
> EMethod.Buffered Or ((FileAccess.Read Or FileAccess.Write) << 14)
>             .
>             .
>    End Enum
>
> Elsewhere, I declare two variables:
>
> Dim X As EIOControlCode = EIOControlCode.FsctlSetCompression
> Dim Y as UInteger
>  Y=(EFileDevice.FileSystem << 16) Or (16 << 2) Or EMethod.Buffered Or
> ((FileAccess.Read Or FileAccess.Write) << 14)
>
> and observe that variable X has the hex value of 639040     (wrong)
> and that variable Y has the hex value of 9C040  (correct)
>
> Note that the code setting Y is exactly the same as the code setting the
> Enum element.
>
> Same code, different results. The only difference is that the Wrong
> results
> are a product of VB.Net's evaluation of the code in the Enum at compile
> time
> whereas the correct results are produced at run time.
>
> The problem, of course is that the EIOControlCode Enum runs to over 100
> entries which I now have to consider suspect at best.
>
> Any help will be appreciated.
> --
> Jim Parsells


Sorry, but I get 9c040 for both values.  Double check your formatting of the
output?  639040 is 9c040 expressed as an integer.

--
Mike
Author
23 May 2009 11:05 PM
Mike
Jim Parsells wrote:
Show quoteHide quote
> Using VS2008 targeted at Framework 2.0 on XP SP3 (32 bit)
>            .
>  FsctlSetCompression = (EFileDevice.FileSystem << 16) Or (16 << 2) Or
> EMethod.Buffered Or ((FileAccess.Read Or FileAccess.Write) << 14)
>              .
> Dim X As EIOControlCode = EIOControlCode.FsctlSetCompression
> Dim Y as UInteger
>   Y=(EFileDevice.FileSystem << 16) Or (16 << 2) Or EMethod.Buffered Or
> ((FileAccess.Read Or FileAccess.Write) << 14)
>
> and observe that variable X has the hex value of 639040     (wrong)
> and that variable Y has the hex value of 9C040  (correct)
>
> Any help will be appreciated.

I can't repeat it.  I get 9C040 for both. How are you displaying the
hex?

         writeline("x = {0,8}",Hex(x))
         writeline("x = {0:X8}",CType(x,Uinteger))
         writeline("y = {0:X8}",y)

    x =    9C040
    x = 0009C040
    y = 0009C040

--
Author
24 May 2009 2:29 AM
Jim Parsells
OK guys ...
Silly me, I had clicked the Hex button in VS2008 and ASSUMED that it would
show me all the values in Hex.  I just never pushed beyond that to see what
the actual hex was for the result it was showing as I hovered the mouse over
the various variables.  Hmmm ... it did show the Hex of everything not
expressed as a member of the Enum in question. Somehow I just missed the fact
that 639040 did not have &H prepended.

Thanks.
--
Jim Parsells


Show quoteHide quote
"Mike" wrote:

> Jim Parsells wrote:
> > Using VS2008 targeted at Framework 2.0 on XP SP3 (32 bit)
> >            .
> >  FsctlSetCompression = (EFileDevice.FileSystem << 16) Or (16 << 2) Or
> > EMethod.Buffered Or ((FileAccess.Read Or FileAccess.Write) << 14)
> >              .
> > Dim X As EIOControlCode = EIOControlCode.FsctlSetCompression
> > Dim Y as UInteger
> >   Y=(EFileDevice.FileSystem << 16) Or (16 << 2) Or EMethod.Buffered Or
> > ((FileAccess.Read Or FileAccess.Write) << 14)
> >
> > and observe that variable X has the hex value of 639040     (wrong)
> > and that variable Y has the hex value of 9C040  (correct)
> >
> > Any help will be appreciated.
>
> I can't repeat it.  I get 9C040 for both. How are you displaying the
> hex?
>
>          writeline("x = {0,8}",Hex(x))
>          writeline("x = {0:X8}",CType(x,Uinteger))
>          writeline("y = {0:X8}",y)
>
>     x =    9C040
>     x = 0009C040
>     y = 0009C040
>
> --
>