Groups | Blog | Home
all groups > vb.net > march 2005 >

vb.net : Using Uint in VB .NET


Howard Kaikow
3/12/2005 7:11:29 PM
C# allows one to specify a constant with a type of uint, so you could have,
say:

private const uint varname = 0xFFFFFFF0

How does one port such statements to VB .NET?

--
http://www.standards.com/; See Howard Kaikow's web site.

Gerald Hernandez
3/12/2005 10:03:37 PM
Even if you get any of these variations to actually compile, it is still of
little use.
While VB.Net (pre 2005) does allow you to declare Unsigned Ints, there are
no operators.
You can add, subtract, etc. not even within the same data type.
Even simple compares will choke in many cases.

Gerald

Gerald Hernandez
3/12/2005 10:08:00 PM
that should read...
You can "NOT" add, subtract, etc...

[quoted text, click to view]

Howard Kaikow
3/12/2005 11:38:53 PM
I had tried something like that.

Error returned is "Value was either too large or too small for a UInt32."

The only things that "work" are

Private ReadOnly varname As Integer = &HFFFFFFF0
Const zz As Integer = &HFFFFFFF0

--
http://www.standards.com/; See Howard Kaikow's web site.
[quoted text, click to view]

Herfried K. Wagner [MVP]
3/13/2005 1:28:12 AM
"Howard Kaikow" <kaikow@standards.com> schrieb:
[quoted text, click to view]

Currently that's not supported by VB.NET because VB.NET doesn't "natively"
support unsigned types (notice that the unsigned types are not CLS
compliant).

Untested:

\\\
Private ReadOnly varname As UInt32 = _
Convert.ToUInt32(&HFFFFFFF0)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Howard Kaikow
3/13/2005 3:57:08 AM
[quoted text, click to view]

I understood that.

Fer now, I'm just passing a constant to a sub/function, so I can get by
cheating with Integer.

Gerald Hernandez
3/13/2005 8:41:08 AM

[quoted text, click to view]

As long as you resign yourself to using bit-wise operations only, then this
is your best bet. It is what I do, and it works quite well. If you need that
extra top bit, then the best thing to do is work with a Long (Int64).
Sometimes that extra bit is all you really need, it seems a shame to waste
another 32. But hopefully this will be solved with VB 2005.

Gerald

AddThis Social Bookmark Button