Results 1 to 7 of 7

Thread: [RESOLVED] Overflow error

  1. #1

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Resolved [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

  2. #2
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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

  3. #3

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    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.

  4. #4
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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.

  5. #5
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    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.

  6. #6

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    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.

  7. #7
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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
  •  



Click Here to Expand Forum to Full Width