Results 1 to 2 of 2

Thread: Overflow (Error 6)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2000
    Location
    Sydney, Australia
    Posts
    196

    Post

    I had this problem today and had to use the prescribed work-around. This is from the msdn library:

    You attempt to use a number in a calculation, and that number is coerced into an integer, but the result is larger than an integer. For example:
    Dim x As Long
    x = 2000 * 365 ' Error: Overflow
    To work around this situation, type the number, like this:

    Dim x As Long
    x = CLng(2000) * 365

    -------------

    This seems a bit stupid. Can't visual basic tell that it's a Long integer. Why does this "coercing" happen. Sounds more like a glitch in the compiler to me. Does anyone know of a better work-around than the one microsoft prescribes?

    Thanks in advance,

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    Yeah I've come across this before as well!

    one way round it is sticking .0 on the end so it becomes single
    VB is so crap er.. I mean weakly typed that it lets you do this.

    Dim x As Long
    x = 2000.0 * 365.0

    ------------------
    Mark Sreeves
    Analyst Programmer

    [email protected]
    A BMW Group Company

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