views:

33

answers:

3

I'm new to VB.Net. I'm using a library call setInstance(ByVal instance As UInteger) in my VB.Net code. The parameter I need to pass is an Integer. Is there anything I need to do to convert the integer parameter to an unsigned integer? The number is garunteed to be positive and less than 10.

+2  A: 

You can call CUint to convert a variable to a UInteger.

SLaks
+2  A: 

Like so...

Dim MyInt As Int32 = 10
Dim MyUInt As UInt32 = CUInt(MyInt)
setInstance(MyUInt)
Carter
A: 

CuInt or Ctype( x, UInt ) allows convert a positive integer.

Throws exception when x is negative.

to Use Int as Uint, you can use some tricks:

  dim bb() = System.BitConverter.GetBytes(myInt)
  dim MyUint = System.BitConverter.ToUInt32(bb, 0)

Also with System.Buffer.BlockCopy for arrays.

If you configure Compiler to disable Check Integer Overflow (Default on Csharp). Then you can use CUint with negative values with no check - not exception.

x77