|
-
Dec 19th, 2007, 05:54 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Overflow error
Hi Guys,
I get an overflow error on this line of code:
Code:
tArrivalKms = CLng(.TextMatrix(j, 6))
The number I entered is 33333335555.
I have declared tArrivalKms as long. In my database I have an Integer field to store the value. What data type must I store this value as. Why am I getting an overflow? Please advise me
Last edited by Nitesh; Dec 19th, 2007 at 05:55 AM.
Reason: additional information
-
Dec 19th, 2007, 06:09 AM
#2
Re: Overflow error
Long can't hold a number that big, the maximum is:
2147483647
33333335555 is too big.
Currency is 64-bit and it can hold the number. Long is 32-bit.
Edit!
Currency's maximum is:
922337203685477.5807
-
Dec 19th, 2007, 06:18 AM
#3
Thread Starter
PowerPoster
Re: Overflow error
ok. thanks for clearing that up for me. What datatype should I make this field in my database. How should I covert it. for example I am using Clng(Number) at the moment. What's the correct one to use for this case.
-
Dec 19th, 2007, 06:26 AM
#4
Re: Overflow error
It is entirely dependant on the database you're using: search for the datatype listing of that database to see the limitations of the datatypes.
CCur() will do a conversion to Currency. You don't need to use identical datatypes if you always use datatypes that can hold a bit bigger than you expect your application to need.
If you need even bigger datatype than Currency, then Decimal will do. It is only usable in Variant datatype and to convert to that subtype you must use CDec(). It can hold very, very big numbers.
-
Dec 19th, 2007, 06:30 AM
#5
Hyperactive Member
Re: Overflow error
you can also use cdbl. It converts to double.
Double maximum is 1.79769313486232E308. But if you dont need such a long number you could use currency.
-
Dec 19th, 2007, 06:33 AM
#6
Thread Starter
PowerPoster
Re: Overflow error
thanks alot. But I think I was a bit mad to post this in the first place as any vehicle wouldn't have such a huge reading on its odometer. so the Integer datatype is sufficient. I was just wondering what would happen if a user entered a really huge number. But I will do some error handling if that occurs.
-
Dec 19th, 2007, 06:37 AM
#7
Re: [RESOLVED] Overflow error
With double the problem is the amount of significant numbers: if we compare Currency and Double in equal level in case of integer usage...
922337203685477.5807
179769313486232.0000
Currency can hold more significant numbers. If you try to store
1797693134862324
into Double you get
1797693134862320
which must be remembered when using floating point numbers. You don't get an error, but you may get results you don't expect.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|