474,015 Members | 1,702 Online

# Why does ?2944*24 in the immediate window give me an overflow error?

?2944*24
gives me an overflow error, entered in the
immediate window. Anybody else?
Nov 13 '05 #1
7 2171
2944*24
gives me an overflow error, entered in the
immediate window. Anybody else?

Important to note is that the following calc's
fine - no error at all...

?2^64
1.844674E+19

Now where's the overflow error?
Nov 13 '05 #2
2944*24
gives me an overflow error, entered in the
immediate window. Anybody else?

Important to note is that the following calc's
fine - no error at all...

?2^64
1.844674E+19

Now where's the overflow error?

And furthermore...
?log(2944)+log( 24)
11.16558
?exp(11.16558)
70656.119394842

Hmmm??? 70656 sounds about right to me.
Where's the overflow at now? How can the
immediate window not know 2944*24 = 70656
and yet know that exp(log(2944)+l og(24)) = 70656?

It sure beats me!
Nov 13 '05 #3
"MLH" <CR**@NorthStat e.net> wrote in message
news:74******** *************** *********@4ax.c om...
2944*24
gives me an overflow error, entered in the
immediate window. Anybody else?

Important to note is that the following calc's
fine - no error at all...

?2^64
1.844674E+19

Now where's the overflow error?

And furthermore...
?log(2944)+log( 24)
11.16558
?exp(11.16558)
70656.119394842

Hmmm??? 70656 sounds about right to me.
Where's the overflow at now? How can the
immediate window not know 2944*24 = 70656
and yet know that exp(log(2944)+l og(24)) = 70656?

It sure beats me!

It looks as though it is trying to fit the product into an integer (and
can't). Not too smart of Access is it. If you force either multiplier to
something other than integer first, it doesn't make that mistake.

?clng(2944) * 24
70656

?2944 * clng(24)
70656

IMHO (OK, not so humble), 2 byte integers on 32 bit systems make no sense.
Microsoft should have dropped 2 byte integers when they made the switch from
16 to 32 bit systems.

--
Randy Harris
(tech at promail dot com)
Nov 13 '05 #4
MLH wrote:
?2944*24
gives me an overflow error, entered in the
immediate window. Anybody else?

VBA is an archaic, inefficient language which sometimes treats literals
inefficiently.
In this case it looks at 2944 and say ... "integer" so
I should try to put 2944 into an integer.
It can't so it reports an overflow.

Dim l As Long
l = 2944
Debug.Print l * 24

This works fine because VBA recognizes l as a long.

It may be helpful to declare all variables and forget literals. I never
use the immediate window (except for debug.print) and am astounded by
the many posts which recommend it.

BTW, this accounts for the nonsense that True=-1.
When we make all the bits in an integer zero we get zero. This is false.
(All the flags are down)
When we do NOT to all those bits we change them all to 1's.
(All the flags are up)

And of course all ones is -1 (twos complement).
So, first VBA decides to treat True as an integer. Because it doesn't
have an unsigned integer it uses a signed integer. Arggggggggggggh .

255 (byte) is, in my opinion a much better numerical equivalent for
true. As a byte is not signed, we don't have the -1 absurdity.

Dim b As Byte
b = True
Debug.Print b '255
--
--
Lyle

"The aim of those who try to control thought is always the same. They
find one single explanation of the world, one system of thought and
action that will (they believe) cover everything; and then they try to
impose that on all thinking people."
- Gilbert Highet
Nov 13 '05 #5
MLH wrote:
?2944*24
gives me an overflow error, entered in the
immediate window. Anybody else?

what they said....

+ a tip for immediate window use, use the old fashioned type casting
suffixes, e.g.
?2944&*24
70656
?3.11-3.1
9.9999999999997 9E-03
?3.11@-3.1@
0.01

A bit quicker to type in than Clng, Cdbl, etc.

The characters are:
%=Integer
!=Single
&=Long
#=Double
@=Currency

--
[Oo=w=oO]

Nov 13 '05 #6
The default data type in VBA is Integer, so any result larger than 32767
overflows.

Convert one of the numbers to a Long, e.g.:
? CLng(2944) * 24
or you could use the type declaration character:
? 2944& * 24

Other typecasting functions: CDbl(), CCur(), CVDate(),...

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MLH" <CR**@NorthStat e.net> wrote in message
news:ff******** *************** *********@4ax.c om...
?2944*24
gives me an overflow error, entered in the
immediate window. Anybody else?

Nov 13 '05 #7
Thanks All.