1

I'm trying to convert some C# code to VB.Net. See the following:

C#:

private const ushort SO_IMAGE_RAW = 1;
private const ushort SO_IMAGE_DIB = 2;
private const ushort SO_IMAGE_DCM = 3;
private const ushort SO_IMAGE_BITDEPTH = 12;
private const ushort SO_IMAGE_FORMAT = SO_IMAGE_RAW;
int format = (SO_IMAGE_BITDEPTH << 16) + (SO_IMAGE_FORMAT & 0x0000FFFF);

From the watcher: format=786433 int // This is correct value.

VB.Net:

Private Const SO_IMAGE_RAW As UShort = 1
Private Const SO_IMAGE_DIB As UShort = 2
Private Const SO_IMAGE_DCM As UShort = 3
Private Const SO_IMAGE_BITS As UShort = 12
Private Const SO_IMAGE_FORMAT = SO_IMAGE_RAW
Dim format As Integer = (SO_IMAGE_BITS << 16) + (SO_IMAGE_FORMAT And &HFFFF)

From the watcher: format=13 Integer '' This is incorrect value.

Any ideas why?

Thanks.

Tiger
  • 45
  • 1
  • 1
  • 3
  • I used a converter to get the VB.net code. – Tiger Apr 04 '14 at 04:04
  • 1
    Converter used: http://www.developerfusion.com/tools/convert/csharp-to-vb/ I tried several converters, but this one actually seemed more reasonable - still didn't work though. – Tiger Apr 04 '14 at 04:04

3 Answers3

1

Change the constants to integers and you get the same result as C#:

Private Const SO_IMAGE_RAW As Integer = 1
Private Const SO_IMAGE_DIB As Integer = 2
Private Const SO_IMAGE_DCM As Integer = 3
Private Const SO_IMAGE_BITDEPTH As Integer = 12
Private Const SO_IMAGE_FORMAT As Integer = SO_IMAGE_RAW

I'm not quite sure why this is necessary, but the following post might shed some light: Binary Shift Differences between VB.NET and C#

Another option - perhaps easier to stomach, is to keep the constants the same, but just use a cast:

Dim format As Integer = (CInt(SO_IMAGE_BITDEPTH) << 16) + (SO_IMAGE_FORMAT And &HFFFF)
Community
  • 1
  • 1
Dave Doknjas
  • 6,394
  • 1
  • 15
  • 28
0

I think you forgot to specify the datatype in this line

Private Const SO_IMAGE_FORMAT = SO_IMAGE_RAW

try changing it to

Private Const SO_IMAGE_FORMAT As UShort = SO_IMAGE_RAW

EDIT:

this is also a great tool to convert c# code to vb.net

Codemunkeee
  • 1,585
  • 5
  • 17
  • 29
0
Private Const SO_IMAGE_RAW As UShort = 1
Private Const SO_IMAGE_DIB As UShort = 2
Private Const SO_IMAGE_DCM As UShort = 3
Private Const SO_IMAGE_BITDEPTH As UShort = 12
Private Const SO_IMAGE_FORMAT As UShort = SO_IMAGE_RAW
Private format As Integer = (SO_IMAGE_BITDEPTH << 16) + (SO_IMAGE_FORMAT And &Hffff)

Convert C# to VB.NET link1

Convert C# to VB.NET link2

Mihai Hantea
  • 1,741
  • 13
  • 16