views:

114

answers:

3

what does this mean?

if CDbl(Trim(Range("M" & r).Text)) > 0# then...

what does the # do?? and what does cdbl do?

+5  A: 

CDbl() convert an expression to a Double:

A data type that holds double-precision floating-point numbers as 64-bit numbers in the range -1.79769313486231E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values.

"#" is the "type-declaration character" for a Double. Following a number with this symbol means that it will treat the number as a double instead of trying to guess what exact variable type to use (it would likely have treated the 0 as a integer without this)

BradC
A similar trick that is useful in some languages (SQL, for one) is to use `0.0` instead of just `0`. This will force it to treat the number as some form of decimal instead of an integer. Not sure if this trick is useful in VBA.
BradC
@BradC - when you type `0.0` into the VBA editor it will actually rewrite it as `0#`
Mike Woodhouse
+2  A: 

CDbl casts the contents to a double value. The # indicates it's a numeric double value. VB and VBA are sometimes quite forgiving when you're dealing with numbers, which can prove to be dangerous!

pm_2
+2  A: 

Visual Basic uses the pound sign (# ) to indicate double-precision values. So 0# enforces to treat this constant as of type double. CDbl converts expression to double type. * Double means double precision floating point.

Andrey