View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
vandenberg p[_2_] vandenberg p[_2_] is offline
external usenet poster
 
Posts: 4
Default A curious OVERFLOW problem

Put a decimal point after the 182.0 and it will work just fine.
Note VBA will put a # sign in place of .0.

You can also make it work with the following:

y1 = 182
Y2 = 182
x = y1 * Y2

I believe the fact that you enter an integer in the expression
over-rides the declaration so the 182*182 is done as integer
and the limit is 32,767. By using the above the conversion takes
place either to specified data type or the default
and then is multiplied, which avoids overflow.

There will problably be other posts with a more lucid explantion.


Pieter Vandenberg

Myles wrote:

: Has anyone attempted to perform 182*182 operation in VBA? The following
: code generates an ovwerflow error in spite of the declarations.

: Sub test()
: Dim x as Long

: x= 182*182 'overflow error on this line
: Msgbox x

: End sub

: The problem persists even with a DOUBLE declaration for x. Treating x
: as a variant either by default (no declaration) or explicitly (by
: declaration) doesn't help either.

: As 181*181=32761, which reminds one of the magical figure 2 ^15 there
: must be some connection here.


: What's happening ?


: Myles


: --
: Myles
: ------------------------------------------------------------------------
: Myles's Profile: http://www.excelforum.com/member.php...o&userid=28746
: View this thread: http://www.excelforum.com/showthread...hreadid=492084