Uint64 / ULong Initialization Problem

john3376

New member
Joined
Oct 25, 2007
Messages
2
Programming Experience
10+
Hello

Was wondering if anybody has run across this in vb.net, VC# works as you would expect.

The vbnet compiler has to be getting confused about what vars are declared signed and unsigned.



In VB.NET
Private ulongNumss0 As ULong = &H7FFFFFFF ' OK
Private UInt64Num0 As UInt64 = &H7FFFFFFF ' OK
Private ulongNumss1 As ULong = &H80000000 ' *Compile Error
Private UInt64Num1 As UInt64 = &H80000000 ' *Compile Error
Private ulongNumss2 As ULong = &H7FFFFFFFFFFFFFFF ' OK
Private UInt64Num2 As UInt64 = &H7FFFFFFFFFFFFFFF ' OK
Private ulongNumss3 As ULong = &H8000000000000000 ' *Compile Error
Private UInt64Num3 As UInt64 = &H8000000000000000 ' *Compile Error

* Constant expression not representable in type 'ULong'


In VC#
private ulong ulongNumss0 = 0x7FFFFFFF; //OK
private UInt64 UInt64Num0 = 0x7FFFFFFF; // OK
private ulong ulongNumss1 = 0x80000000; // OK
private UInt64 UInt64Num1 = 0x80000000; // OK
private ulong ulongNumss2 = 0x8000000000000000; //OK
private UInt64 UInt64Num2 = 0x8000000000000000; // OK
private ulong ulongNumss3 = 0xFFFFFFFFFFFFFFFFF; //68 bytes = *Expected Error
private UInt64 UInt64Num3 = 0xFFFFFFFFFFFFFFFFF; //68 bytes = * Expected Error

* Integral constant is too large


JB


Microsoft Visual Studio 2005
Version 8.0.50727.42 (RTM.050727-4200)
Microsoft .NET Framework
Version 2.0.50727

Installed Edition: Professional

Microsoft Visual Basic 2005 77626-009-2404065-41121
Microsoft Visual Basic 2005

Microsoft Visual C# 2005 77626-009-2404065-41121
Microsoft Visual C# 2005
 
Maybe this will help somebody else.

You need to use UL(Unsigned Long) after the hex number as in:

In VB.NET
Private ulongNumss0 As ULong = &H7FFFFFFFUL ' OK
Private UInt64Num0 As UInt64 = &H7FFFFFFFUL ' OK
Private ulongNumss1 As ULong = &H80000000UL ' OK
Private UInt64Num1 As UInt64 = &H80000000UL ' OK
Private ulongNumss2 As ULong = &H7FFFFFFFFFFFFFFFUL ' OK
Private UInt64Num2 As UInt64 = &H7FFFFFFFFFFFFFFFUL ' OK
Private ulongNumss3 As ULong = &H8000000000000000UL ' OK
Private UInt64Num3 As UInt64 = &H8000000000000000UL ' OK

JB
 
Back
Top