How to pass integer as unsigned parameter in 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 guaranteed to be positive and less than 10.

Answers


Like so...

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

CUInt or CType(x, UInt) allow converting a positive integer.

It throws an 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 the compiler to disable Check Integer Overflow (default for C#). Then you can use CUInt with negative values with no check - not exception.


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


Need Your Help

SQL utl_raw.cast_to_raw XML Delimiter for single quotes

sql xml delimiter

I am trying to insert some XML data into a blob column using utl_raw.cas_to_raw.

Use SQL Certificate from another database

sql-server-2008 encryption certificate

I have database A in this database there is a certificate and a table. I want to insert an encrypted value into a table which is in database A. The stored procedure is in database B and would ideally