OVERFLOW during calculations

JRG0620

Registered User.
Local time
Today, 14:48
Joined
Nov 23, 2008
Messages
20
I am trying to multiple a datbase integer by 100 and I get a dialog box that all it says is overflow. When I take the * 100 off the format, everything works fine but the number is not correct. My statement is as follows:

MyQualcost = IIf(IsNull(MyTable![Qualcost]), zeroes, Format(MyTable![Qualcost] * 100, "00000000000;"""))

MyQualcost is defined as an integer both within my VB code as well as the database. If my database fields is 123456, I need my extract record to be 12345600.

How do I get around the overflow error??? Thanks
 
Your source table and the field in question will be set as an Integer you will need to change this to Long Integer as the newly generated number exceeds the highest number that can be applied to an integer type field.
 
DCRAKE,

Thanks for the quick reply. That got me around the overflow issue but now it changed my record formats. Before changing the fields to 'Long', the formats were what I needed to match the next program. Since I changed to 'Long' my record length is now shorter than before. Solve one problem.....create another. I love programming.

Thanks for your help
 
yep

an integer is two bytes, so can hold 2^16 = 65536

because it holds positives and negatives the range is actually something
like -32767 to +32768

a long integer is 4 bytes so is 2^32 = (65536 squared) 4billion approx,
and because of positive/negatives is actually -2 billion to +2billion
 
I need a little more help in this area: On the table my fields are classified as 'Double'. Within my program I have them defined as 'Long'. The issue now is when I calculate the result by taking the table field * 100, everything works well until I reach a table fields that is 99999999 or greater in length. If I hit this length, I once again get the overflow message. If the table field is less than this length, I can multiply it by 100 and then format it into a fixed length 11 digit number with no problems.

Any ideas on what I'm doing wrong. Thanks again.
 
NEVER MIND. I tried changing my program's DIM statements to be Double instead of Long and that appears to have worked. Not sure what all the differences are but the data now seems to be correct.
 
Be aware that Double can introduce rounding errors due to how it is stored. If you intend to do comparison and need it to be precise to the last digit, consider using decimal, or storing the number as text if you don't need to do arthimetric operations.
 
>> consider using decimal <<

The DECIMAL datatype has its own issues and is (IMHO) difficult to work with in VBA, since there the Decimal datatype needs to be stored in the Variant datatype. I personally would consider using the Currency datatype (not to be confused with the Currency Format of a Number/Single or Double) if your number does not exceed the need for 4 decimal places ... Check out http://www.utteraccess.com/forums/showflat.php?&Number=1205893&fpart=1#Post1205893 for more info on float vs fixed point numbers if you are interested.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom