Decimals

  • Thread starter Thread starter mo
  • Start date Start date
M

mo

Anyone have any idea (Ac2000) why when I write '3.0' in a module, Access
then changes it to 3# when I move onto a new line of code?

Is this default behaviour?

TIA

E.g: If x >= 3.0.....
becomes If x >= 3#
 
This is normal, and not a problem.

Access sets aside memory to store any value you enter, even a literal. If
you enter just 3, VBA sets aside 2 bytes and stores it as an Integer. If you
enter 3.0, VBA thinks you are trying to specify a fractional number, so it
sets aside 8 bytes and stores it as a Double.

The "#" is the type declaration character for a Double, i.e. VBA is
indicating to you that it has stored this literal value as a Double (not
Single, or some other type).

The type declaration characters are actually quite useful like this. For
example, VBA returns the length of a string as a Long Integer. The type
declaration character for a long is ampersand. If you type:
If Len(str1) > 0 Then
Access stores the zero as an integer, and has to convert it to a Long at
runtime before it can make the comparison. It is therefore (fractionally)
more efficient to ask it to store a Long to begin with, i.e.:
If Len(str1) > 0& Then

To ask Access what type it is using for something, use TypeName() in the
Immediate Window (Ctrl+G), e.g.:
? TypeName(3#)
 
Back
Top