Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Type Differences

Status
Not open for further replies.

kimble

Technical User
Aug 23, 2001
107
0
0
US
I'm having a problem with storing large numbers in an array. When I try to assign a 20 digit number from a text box to a variable I get an overflow error. What data type should i assign my variables to allow for these large integers? I've tried Integer and Long.

Here is a simple example:
Placing 123456789123456789 in the textbox

Dim I As Long
I = Text1.Text
MsgBox I

I get 'Run time error' Overflow 6

Any Ideas?
 
kimble,

Yep, use Double.

From VB help:

"Long (long integer) variables are stored as signed 32-bit (4-byte) numbers ranging in value from -2,147,483,648 to 2,147,483,647. Thetype-declaration character for Long is the ampersand (&)."

Your number is too long. Whereas Double datatype:

"Double (double-precision floating-point) variables are stored as IEEE 64-bit (8-byte) floating-point numbers ranging in value from -1.79769313486232E308 to -4.94065645841247E-324 for negative values and from 4.94065645841247E-324 to 1.79769313486232E308 for positive values. Thetype-declaration character for Double is the number sign (#)."

Much larger range. Hope that helps.

-crater

 
Is there anyway to store a number longer than 308 digits?
 
I can't actually think - at the moment - of an application that VB is suitable for that would require such an ability. Could you enlighten me?
 
Kimble,

Yeah, what are you trying to do that will require more than 308 digits? That's one heck of a huge number.

-crater
 
I wrote a prime number algorithm that can find primes between two numbers fast. I used VB cause it was easy. I do know Fortran so maybe I'll try to switch it over and see how long a digit number i can create. Right now the largest known prime numbers have ~ 2 million digits in them.
 
kimble,

I'm sorry to say, but VB isn't your best option for that I don't think. You won't find a single data type that will take a number with 2 million digits. Not only that, but I don't think you will find any language that has a data type that big.

What you will need to do is to create an array of 2 million items where each item is a digit. Then you can manually manipulate (remember elementary school math where you had to do each digit at a time?) the numbers.

For your problem I might suggest something a little more mathematically oriented. Something of the C/C++ variety.

Hope that helps a bit.

-crater
 
Can you even create an array of 2 million items in any language?
 
Sure. It just might be slow. And you gotta have enough RAM/Swap Space.

Linked list works well for that too. You don't have a size limit (other than physical limitations like RAM) because there is no counter involved. Arrays might have counters for which 2 million items will overflow.

-crater
 
You can always store huge numbers as a string variable. Sadly, VB's standard mathematical operators do not support them. There aren't any built-in function neither.

Fortunately there are some clever and courageous programmers who did the work: it's up to you to grab it at: _________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top