Re: Declaration problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




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?action=getinfo&userid=26538
View this thread: http://www.excelforum.com/showthread.php?threadid=398008

.



Relevant Pages

  • Re: Freeing Algorithms
    ... On the other hand, int is simple, efficient, and handles very ... The data type int falls somewhere before the requirement of the user. ... To paraphrase the requirement (since requirements cannot be accurately expressed in English (or a programming language for the Mr. TDD!)), a data type that extended between negative and positive infinity is required to express the arrow of time. ... Assuming Java provided a data type that permitted an extension to infinity, then it would certainly make int look like hitherto "overkill". ...
    (comp.lang.java.programmer)
  • Re: User Input issue
    ... now we know that the int data type uses 4 bytes of memory. ... You wrote a moment ago that the programmer does not ... covered strings yet (I'm a college freshman in a Programming I/Novice ...
    (comp.lang.c)
  • RE: time_t size and year 2038 wrap
    ... > as long int. ... > redhat site for date 2038 and found very little current ... To bullet proof your code, you could declare a data type, ... or manipulations on your special versions of date-time. ...
    (RedHat)
  • Re: Working with Cash and uses of Typedef
    ... Which data type should I use instead? ... If you're tracking tenths of pennies, that same 16 bit int ... Abstraction is a powerful tool, and when done properly can make life ...
    (comp.lang.c)
  • User Input issue
    ... now we know that the int data type uses 4 bytes of memory. ... either a C-style string or C++ string and then use the stdlib header ... covered strings yet (I'm a college freshman in a Programming I/Novice ...
    (comp.lang.c)