What's the difference between Val() and CDbl()?

keirnus

Registered User.
Local time
Tomorrow, 04:38
Joined
Aug 12, 2008
Messages
99
Hello,

I'm just wondering about Val() and CDbl() functions. :(

I know Val() accepts String arguement and returns Double data type.
While CDbl() accepts Expression arguement and returns Double data type as well.

Q1: What is "Expression"?
- a data type or what?

Q2: What's the difference between Val() and CDbl()?
- does it have to do with Access versions? MS Office versions?

Q3: When to use Val()? CDbl()?

I know some of you already know this but not me. So, pls bare with me. :o
That's why I posted it here to ask help and get explanations from the "experts". ;)

This post could be informative in the near future. :)
 
Hmm, didn't realize there were two things.

But I can tell you this:

Expression isn't a data type, but rather indicates that it can accept any data type, then VBA will try it best to typecast it, whereas Val is more picky.

So, if I had a integer variable, I could use Cdbl() to convert the integer to a double, but Val() would raise a error because it'd be expecting a string.

Furthermore, I'd expect that Val() to be faster (on order of 2 or 1 millsecond; maybe even less than that) than Cdbl() because there's no typecasting needing to be done.

HTH.
 
Val() extracts LEADING numeric characters from a string. It probably recognizes a period but that would be it. It stops at the first non-numeric character. So 2,334 would end up as just 2.
 
Val() extracts LEADING numeric characters from a string. It probably recognizes a period but that would be it. It stops at the first non-numeric character. So 2,334 would end up as just 2.

Actually, Val(2,334) would yield a "invalid number of arguments" error. But, Val("2,334") would yield 2.

I know you said string, but it escaped me at first.
 

Users who are viewing this thread

Back
Top Bottom