Hello all, thank you for considering my question.
I wrote a function for calculating Freight class. It’s very easy: multiply inches of Length*Width*Height and divide that number by 1728. That’s your Cubic Footage. Then, divide Weight by that number.
As you can see, I defined the L/W/H arguments for my function as Integers, which I understand has an upper limit around 32,000 and cannot contain a decimal place. No big deal I thought. This function will always be called where L/W/H are supplied as low whole numbers. As an example, 65x40x14. See? Low, whole numbers.
Weirdly, my function gives me an “Overflow” error. The highlighted offending line is ultimately getting stored into a Double datatype. I’d have figured that Double was beyond sufficient to contain the result of this math.
But the part that is most perplexing is how I resolved the error, and this is what I want you to comment on: I simply went into the topmost line and changed the datatype of all 4 arguments (nLength… etc) FROM integers TO doubles. All of a sudden it works perfect!
But why? The 4 arguments, back when I called them Integers, never once contained a decimal value or were challenged by being too high or low. Their values are absolutely in range. Furthermore, the dblDensity variable is already a double and should be able to handle these numbers easily. In the example you see crashing in the screenshot below, the value of dblDensity would be 77.5 not exactly a challenge for a double datatype.
So what is the significance of changing the 4 integer arguments into double datatype that it suddenly works???
Afterthought: I checked this function again later, leaving out the Weight division. It still errors. It’s something about the Density. See the MsgBox in the line below? It should read something like 14.xxxxxxxxx many decimal places. But since storing this value should have nothing to do with the integer datatypes supplied for the equation, I don’t see why this would cause an overflow.
![]()