Connecting Tech Pros Worldwide Forums | Help | Site Map

OverFlow - Runtime Error 6

Member
 
Join Date: May 2007
Posts: 63
#1: Jan 12 '08
Expand|Select|Wrap|Line Numbers
  1.   Dim tempLeft As Long
  2.   Dim tempWidth as integer
  3.  
  4.   tempLeft = Round(((tempWidth - i) * 100) / 18.39, 1)
  5.  
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??

Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,748
#2: Jan 13 '08

re: OverFlow - Runtime Error 6


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.
Reply