VB6 Overflow error

Thread Starter

Engr

Joined Mar 17, 2010
114
Hi,

I need some help with my VB6 code.

I have a variable in my code set as long. As what I understand in programming, if the variable is set as integer it can only handle up to 32000 numbers and if it is set to long it can handle up to 2000000 numbers. My variable is equal to the product of 188 * 366 (variable = 188*366). Even if it is set as long I am still getting an "over flow" error but if I hardcode the variable = 1000000 the "over flow" error is not showing up. 1000000 is greater than 188*360 (= 67680) but I am not getting the over flow error in 1000000. Can anyone help me with this?
 

BMorse

Joined Sep 26, 2009
2,675
Make sure that numbers used in calculations that are coerced into integers do not have results larger than integers. One way to avoid this is to assign each value to a variable that is declared as a Long Integer, this should get you by this error.....

Rich (BB code):
Dim product As Long
Dim first_val As Long
Dim second_val As Long
first_val = 188
second_val = 360

product = (first_val * second_val)
Text1.Text = product
 

Thread Starter

Engr

Joined Mar 17, 2010
114
Make sure that numbers used in calculations that are coerced into integers do not have results larger than integers. One way to avoid this is to assign each value to a variable that is declared as a Long Integer, this should get you by this error.....

Rich (BB code):
Dim product As Long
Dim first_val As Long
Dim second_val As Long
first_val = 188
second_val = 360

product = (first_val * second_val)
Text1.Text = product
Hi BMorse,

I already tried that approach and still encountered the same problem. All variables set as integer has been changed to long and still the over flow error occurs.
 

BMorse

Joined Sep 26, 2009
2,675
I tried it the same way as you had it at first, i got the error also, but when i declared those variables and assigned them the values and the error went away. . . If you are still having issues, then you need to post your code so we can see what else may be causing it.
 

Thread Starter

Engr

Joined Mar 17, 2010
114
I didnt post the code since it is very long but I think I have already found the solution. I used VB net and the over flow error went away.
 
Top