OverFlow - Runtime Error 6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amolbehl
    New Member
    • May 2007
    • 63

    OverFlow - Runtime Error 6

    Code:
      Dim tempLeft As Long
      Dim tempWidth as integer
      
      tempLeft = Round(((tempWidth - i) * 100) / 18.39, 1)
    Hi,

    When I try to run this code and when tempWidth = 343, I get Runtime error 6 - overflow.

    I have no idea how to get rid of it ... can anyone please help me with this??
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Use Long instead of Integer, perhaps.

    Keep in mind, VB will do the calculation using the smallest data type it thinks it can get away with. So if you force all the values to be seen as Long (or Single, or anything big enough) it will work.

    By the way, just out of curiosity, what data type is i? And while we're at it, the value?

    Hm... what version of VB are you using? I just pasted your code into VB6, inserted tempWidth = 343 and it worked OK.
    Last edited by Killer42; Jan 13 '08, 08:26 AM.

    Comment

    Working...