Data Type Conversion bug??

  • Thread starter Thread starter Randall Banning
  • Start date Start date
R

Randall Banning

With VS2003 I get the following problem:

This works in C#...
{
ulong u=0xF070061073000000; <-no problem initializing variable to
this value
Console.WriteLine(u);
}


But this fails in VB.NET...
Dim u As UInt64 = Convert.ToUInt64(&HF070061073000000) <-Overflow error
here!
Console.WriteLine(u)


Why am I able to initialize the variable in C#, yet intializing to the same
value in VB.NET dies? A ulong and a UInt64 are both the same underlying
framework datatype, a System.UInt64, so what's the problem?

Am I missing something here? Is there a workaround?

Randall
 
Randall,
VB.NET does not understand unsigned numbers!

Using ildasm.exe: VB.NET is attempting to call Convert.ToUInt64(Int64).

Seeing as you are attempting to put a massively negative number (long) into
a unsigned value, it is throwing the exception.

C# works because C# understands unsigned numbers. CSharp is calling
Convert.ToUInt64(UInt64).

Remember in VB.NET (&HF070061073000000) is a Long value, there is no ULong
in VB.NET (yet).

As it stands now you will need to wait for the next version of VB.NET
("Whidbey" (2004)) to get support for unsigned values.
http://msdn.microsoft.com/vstudio/productinfo/roadmap.aspx

Hope this helps
Jay
 
Thanks Jay for the answer. I'm not saying I like it <g>, but it's an answer.

Ok, what I'll do is build what I want into a separate C# DLL then reference
that in my VB project. It's not an ideal solution but it'll hold me until
2004.

Randall
 
Back
Top