Re: Another VBA bug
- From: "Peter T" <peter_t@discussions>
- Date: Mon, 14 Jan 2008 22:45:15 -0000
Hi again,
Several interesting observations. FWIW cell's numberformat works similarly
to your Format example, ie an exact .5 always rounds up. If anything I would
have expected it to truncate down.
Well, I think both the Cxxx functions and IsNumeric are to "generous" in
what they consider numbers. Why is a number with a minus sign in both the
front **and** back considered a valid number?
I don't know about 'too generous', why not 'helpfully accommodating' <g>
As for "both front **and** back", I take it you mean either/or and not both
together. "-123-" fails, but why shouldn't "123-" be allowed to evaluate, or
rather coerce to a valid number.
If one accepts the IsNumeric function is consistent with 'can cDbl without
error' and 'is not a date' (as documented), perhaps it should not be
considered as buggy!
Regards,
Peter T
"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@xxxxxxxxxxxxxxxxx> wrote in
message news:OMmvvXvVIHA.748@xxxxxxxxxxxxxxxxxxxxxxx
toOK we agree that
cDbl("($1,23,,3.4,,,5,,E67$)") ' change '$' to local currency symbol
returns a value and also the string will coerce to a number if assigned
be,a
variable declared as a double.
Therefore surely we should expect IsNumeric to return true when testing
that
string, which it does however surprising at first it may seem. So I'm
wondering after all that, is there anything actually unreliable or buggy
about IsNumeric.
Well, I think both the Cxxx functions and IsNumeric are to "generous" in
what they consider numbers. Why is a number with a minus sign in both the
front **and** back considered a valid number?
However I still suspect Help might be better written along the lines I
suggested using the word 'coerced' vs 'evaluated',
Agreed
''' Date
Debug.Print IsNumeric(Date) ' false as per help
s$ = Format(Date, "mmm dd yyyy")
dt = s ' OK
dbl = CDate(s) ' OK'
dbl = s ' error
'can only coerce to variable declared 'As Date'
In your last statement, the variable 's' is a Variant of sub-type String,
but that String value is no different to the assignment than a/b/c would
so I understand that type mismatch error.know
btw, behind the scenes is there any difference between doing
dbl = s vs dbl = cDbl(s) ?
Well, technically, I think yes. Using CDbl specifically casts 's' as a
Double before the assignment is made. Just assigning 's' directly to 'dbl'
means VB's type coercion mechanism has to decide what to do... while I
it doesn't do this, it could theoretically cast it internally to a SingleCDbl(Now)
(losing precision) first before deciding it should be a Double. As I said,
I'm positive it doesn't do this, but why leave the job to chance when you
know what it should be?
I guess for consistency the authors thought best to exclude dates from
being
considered IsNumeric, ie depending on the string the date may or may not
simply coerce to a number.
What I don't understand is why IsNumeric(Now) returns False while
evaluates to a value (and, of course, the example I gave earlier). IfRounding
IsNumeric is a "proofer" for the Cxxx functions, why not handle this also?
Concerning the Integer divisor: I had been aware of it's Banker's
usesnature for a long time but was surprised once to be hit with something
like
this:
n = 4 \ 0.5 ' error div by zero
Yeah, I got caught with that one too. As a point of information, VB/VBA
Banker's Rounding in every situation where rounding is necessary EXCEPT
inside the Format function. The Format function uses what I consider to be
normal rounding rules (5's are always rounded upward)....
Print Format(5/2, "0") ====> 3
Rick
.
- References:
- Another VBA bug
- From: Don Wiss
- Re: Another VBA bug
- From: Rick Rothstein \(MVP - VB\)
- Re: Another VBA bug
- From: Peter T
- Re: Another VBA bug
- From: Rick Rothstein \(MVP - VB\)
- Re: Another VBA bug
- From: Peter T
- Re: Another VBA bug
- From: Rick Rothstein \(MVP - VB\)
- Another VBA bug
- Prev by Date: VBA to set focus back to exel
- Next by Date: Re: WHY Wont ThiS WoRk Somone Anyone Help !
- Previous by thread: Re: Another VBA bug
- Next by thread: Automation of report, daily, monthly then yearly as per need
- Index(es):
Relevant Pages
|