overflow problem

vb6 Grenada
  • 14 years ago

     i have the code like this

    dim a as long

    a=36693

    print a

     

    in the above case i am not getting any error

    but for the below code i am getting overflow error eventhough the value of a is same that is 36693

    dim a as long

    a=9*4077

    print a

     

    please clear my doubt

     

     

  • 14 years ago
    Hi Harish

    The problem, in fact, is that when multiplying to Integer values VB assumes that the result is also an Integer. If you aren't sure that this is correct, just force either operand to be a Long, as in


    Dim a As Long
    a = 4077 * 9&
    Print a



    Or

    Dim a As Long
    a = 4077 * CLng(9)
    Print a

    I hope this will solve ur problem

    Good Luck

    Regards
    Hari K



















Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Beware of bugs in the above code; I have only proved it correct, not tried it.” - Donald Knuth