tags:

views:

388

answers:

5

Hi,

I'm having an overflow error in VB 6.0 when using the Clong datatype because of really big values. How to overcome this? Is there anything else available higher than the Clong datatype?

+2  A: 

You could use a Double instead of a Long since it can hold larger numbers. The function is CDbl() instead CLng().

In VB6.0, a Long is 32-bits and can hold values up to: 2,147,483,648
A Double is 64-bits and can old values up to: 1.79769313486231570E+308

EDIT: Please refer to this reference

Jose Basilio
Be careful! A double doesn't actually hold more precision, though it can hold larger numbers. Doubles on most systems are rounded to somewhere around 15 digts. For example, 123456789012345678901234567890 will become 1.2345678901234568e29.
Curt Sampson
Curt is basically right. Although a Double _does_ have more precision than a Long, of course: a Long has 10 significant figures and a Double has 15 or 16. And, Jose, why not link to the VB6 reference manual? http://msdn.microsoft.com/en-us/library/aa263420(VS.60).aspx
MarkJ
A: 

I believe the upcoming VB in MSVS2010 has the CLonger (64 bits), CEvenLongerYet (128 bits) and CTooDamnLongForSensibleUse (256 bits) data types.

</humor>

paxdiablo
For a minute there, I thought you were being serious... LOL
Jose Basilio
I'm curious, José. Which of the three data types actually convinced you I wasn't being serious? I would hope it wasn't the CTooDamnLongForSensibleUse one :-) Or worse yet, the closing humor tag :-)
paxdiablo
You had me at CLonger :-p
Jose Basilio
Actually there's going to be a CEvenLongerThanCTooDamnLongForSensibleUse type aka BigInteger in .NET 4.0: http://blogs.msdn.com/bclteam/archive/2007/01/16/introducing-system-numeric-biginteger-inbar-gazit.aspx
Joe
+5  A: 

Depending on how big your really big values are, the VB6 Currency data type might be a good choice.

It supports values in the range -922,337,203,685,477.5808 to 922,337,203,685,477.5807.

Joe
+1  A: 

Here are some options from the VB6 reference manual topic on data types

  • Long (long integer) 4 bytes -2,147,483,648 to 2,147,483,647
  • Single (single-precision floating-point) 4 bytes -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values. About 6 or 7 significant figures accuracy.
  • Double (double-precision floating-point) 8 bytes -1.79769313486231E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values. About 15 or 16 significant figures accuracy.
  • Currency (scaled integer) 8 bytes -922,337,203,685,477.5808 to 922,337,203,685,477.5807
  • Decimal 14 bytes +/-79,228,162,514,264,337,593,543,950,335 with no decimal point; +/-7.9228162514264337593543950335 with 28 places to the right of the decimal; smallest non-zero number is +/-0.0000000000000000000000000001
MarkJ