Unexplained problem with Overflow Error 6

Kelvin Stott

Active Member
Joined
Oct 26, 2010
Messages
338
I have tracked down an overflow Error 6 to the following line:

dMax = Int(s * DPoints / SPoints)

Where all variables are defined as Integers. The error goes away when I define s as Long, but I don't understand why this should be required since none of the individual variables ever exceed the scope of an Integer (-32768 to 32767).

Strangeley, I get the same overflow problem when I type either of the following calculations in the immediate window:

? Int(328 * 100 / 1000)
? 328 * 100 / 1000
? 328 * 100

Note that no variables are defined, so why the overflow problem? Surely Excel/VBA should be able to work with this very basic calculation without any problem, by assigning the appropriate dimension, no?

Is this a known problem with Excel/VBA?

PS. I am using Windows 7, with Excel 2010 (updated from 2009).

Thanks for any help,

Kelvin
 
Last edited:
PS. Even the Long format can overflow:

? 1000000 * 1000000 -> Overflow

Whereas:

? 1000000 * 1000000.0 = 1000000000000 (no problem)
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Using a higher datatype than is necessary can effect performance.
Double takes up more space in memory than Integer.
And it takes longer to read the double than to read the integer.

Kinda the whole reason for having so many different datatypes.
You can control how much memory is occupied by your variables depending on the context of your code.

Otherwise, MS could have just created 1 datatype for all types of numbers (double)
 
Upvote 0
So it's important to strike a balance between option 1 (performance) and option 2 (reliability)...

PS. This has been a great discussion, thanks. I hope it will be useful to others.

I'll leave you alone now. ;)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,820
Members
449,469
Latest member
Kingwi11y

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top