View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Type of variables and their effect on result...

On Fri, 29 Dec 2006 23:13:26 -0500, "MichDenis" wrote:

Thanks for this explanation. I already knew it !

If your suggestion is true, Why do we get different results
simply by using and defining or not the type of the variables as
suggested by my question ?

More than that, if you put this formula in a cell the
result is good : = Int(37.7266 * 10000)
= 377266

In a VBA window, X = Int(37.7266 * 10000)
X = 377265

Is the binary systems of numbers compute differently in each case
based on the presentation of the formula ?

If anyone has a supplement of information, I would appreciate.

Thanks for your collaboration.



Hopefully someone like Jerry Lewis will notice this thread and give some
definitive information.

Although binary computation should work the same all over, the degree of
precision, and some assumptions made by the programs (Excel vs VBA) are
different.

I have read that Excel makes some assumptions to try to minimize the effects of
binary "inexactness".

In VB, the degree of precision can vary, depending on variable types. An
"undefined" variable type will be defined as a variant, and will retain the
data type of the entered value, unless ... (from HELP):

Generally, numeric Variant data is maintained in its original data type within
the Variant. For example, if you assign an Integer to a Variant, subsequent
operations treat the Variant as an Integer. However, if an arithmetic operation
is performed on a Variant containing a Byte, an Integer, a Long, or a Single,
and the result exceeds the normal range for the original data type, the result
is promoted within the Variant to the next larger data type. A Byte is promoted
to an Integer, an Integer is promoted to a Long, and a Long and a Single are
promoted to a Double. An error occurs when Variant variables containing
Currency, Decimal, and Double values exceed their respective ranges.

Sorry I don't have any more than this very superficial explanation.


--ron