View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Simon Murphy[_7_] Simon Murphy[_7_] is offline
external usenet poster
 
Posts: 1
Default Declaration problem


David
sorry I should have been clearer
x is not overflowing, the result of your formula is overflowing. The
issues isn't so much what x can and can't do, but how VB guesses the
data type of a formula result. (hence why 38000-8000 fixes it)
effectively you are taking a short cut from this:

result = x*30000
Cells(x, 1).Value = result

The question is what is the type of result?
answer: most programming languages assume the largest data type of any
of the arguments, which is why changing one to a long fixes it.

If you replace your short version with the 2 lines above and dim result
as a long then the problem is still there. VB internally apparently
can't calculate x*30000 where x is an int 1.

So your observation is right - the data type does have a big impact on
what can be done with a variable, and part of that is how VB guesses
the data type of a formula result, based on the data type of all the
arguments

I rarely use ints anyway in VBA, I mainly use longs.

cheers
Simon


--
Simon Murphy
------------------------------------------------------------------------
Simon Murphy's Profile: http://www.excelforum.com/member.php...o&userid=26538
View this thread: http://www.excelforum.com/showthread...hreadid=398008