Re: Coerce Null to Zero?
- From: "Dmitriy Antonov" <antonovdima@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 10 Oct 2006 21:23:52 -0400
"Dmitriy Antonov" <antonovdima@xxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:u9%23iJGN7GHA.2384@xxxxxxxxxxxxxxxxxxxxxxx
"Karl E. Peterson" <karl@xxxxxxxx> wrote in message
news:OL6ZCjL7GHA.4552@xxxxxxxxxxxxxxxxxxxxxxx
Just wondering... When working with database fields, it's simple to
coerce
a Null to String by concatenating an empty string. IOW:
MyField & ""
Is there a similar technique for coercing it to Zero with numeric fields?
I
swear I remember knowing of one at one time, but ...? All I can think of
is:
Val(MyField & "")
Sure seems klunky.
Thanks!
--
Working without a .NET?
http://classicvb.org/
(Null And 0)
Try
?5 + (Null And 0)
5
But I generally prefer to use generic function. Something like this (got
idea from MS Access):
public function nz(Value as Variant, optional ValueIfNull as
Variant=vbNullString) as Variant
if isnull(Value) then nz=ValueIfNull Else nz=Value
end function
So any of the following should work with numeric (integer) value:
lRes = nz(Null, 0)
lRes = Val(nz(Null))
I prefer an empty string to zero as a default value, because it is easier
to convert to zero from an empty string then vice versa.
Should be adjusted if objects can be considered, but, generally, no need
for this.
Dmitriy.
I probably had a bad day today.
Please disregard the first part - of course ANDing a variable with zero is
not going to work (and doing it with a constant does work but doesn't make
any sense). So I would stick to just a function.
Dmitriy.
.
- References:
- Coerce Null to Zero?
- From: Karl E. Peterson
- Re: Coerce Null to Zero?
- From: Dmitriy Antonov
- Coerce Null to Zero?
- Prev by Date: Re: Coerce Null to Zero?
- Next by Date: Re: Coerce Null to Zero?
- Previous by thread: Re: Coerce Null to Zero?
- Index(es):
Relevant Pages
|