Overflow with ULong type

Andrea Lanza

New member
Joined
Jan 17, 2006
Messages
2
Programming Experience
Beginner
Hi all from Italy,
I have installed Visual Studio 2005 on a x64 Intel machine.
When I try to assign the maximum value possible for a ULong variable, I got an overflow error:

dim Var1 as ULong
Var1 = 18446744073709551615 '<-- overflow

This happens immediatly at design time and also with other big numbers.
Anyone can explain to me why this error occur?

Thank's a lot
Andrea
 
The problem is the fact that numeric literals default to the Integer type, so you are trying to use an Integer literal with the value 18446744073709551615 and BOOM, overflow. You can force literal values to particular types with the appropriate suffix. In the case of the ULong type the suffix is "UL", so try:
VB.NET:
 Var1 = 18446744073709551615UL
Welcome, by the way. I just noticed your post count.
 
The issue is not the variable type but the literal type. I imagine that the whole idea of using a ULong is so that the value cannot be negative and must be integral. You lose those characteristics if you use the Decimal type.
 
Also Andrea, you may already be aware of this but the ULong type has a Shared MaxValue property that you can use to get the maximum allowable value for the type, as do all numerical types if I'm not mistaken.
 
Hi and thank's for the help.
I'm developed a chess engine in Visual basic 6 (www.cds.pc.it/Matilde) and now I want to rewrite it in VB 2005 using Bitboard and working with 64 bit number. This is why I need long integer...

Bye all...
Andrea
 
Back
Top