How do I coerce the result of &h into a UInt32 if I already know the value is in the legal range?

I searched the forum and docs then web searched and couldn’t find a definitive answer.

const k1 as UInt32 = &h1
var i1 as UInt32 = &h2

Is the use of a var or const the only option? The context is that I’m passing an Array() of &h values to code that expects a UInt32 Array.

See my example code here:

Maybe I am dense but can’t you just use:

Integer.FromHex

??

I’m assuming all of your hex strings are preceded by &h? Then use code like this:

Dim HexArray as String
Dim IntArray() as UInt32

For i as integer = 0 to HexArray.Ubound
  IntArray.Append Integer.FromHex(HexArray(i).Right(HexArray(i).Length-2))
Next

Then pass IntArray to your method.

Edit:

Or to be more politically correct:

VAR HexArray as String   // I HATE VAR
VAR IntArray() as Unit32 // I HATE VAR

For i as integer = 0 to HexArray.Ubound
   IntArray.AddRow Integer.FromHex(HexArray(i).Right(HexArray(i).Length-2))
Next

Thank you! Somehow I missed the existence of Integer.FromHex in the docs.

1 Like