Search code examples
vb6

Why does long l = 1000 * 60 cause overflow?


I have this line:

    Dim l&
    l = 1000 * 60 '1 min

It throws an overflow error.

Why is that?


Solution

  • Vb's Help says:

    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