Handling of unsigned values?

Why is this code not compiled

Const UnsignedValue As UInteger = &H80004005

To make it more strange this compiles:

Const UnsignedValue As Integer = &H80004005

The value is larger than Integer.MaxValue but smaller than UInteger.MaxValue.

 



Answer this question

Handling of unsigned values?

  • shunm_ms

    Thank you for this information.

     


  • IngJVV

    No problem :)

  • Samuel D. Colak

    In VB, literals (including hexadecimal literals) are considered to have type integer - as such &H80004005 is actually a negative number (representation in two's complement) - so in your first statement you're trying to assign a negative integer to an unsigned variable, and in the second statement you're assigning a valid negative number to an integer variable.

    Use &H80004005UI to specify that the variable is mean as an unsigned type



  • Handling of unsigned values?