Re: Coerce Null to Zero?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"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.


.



Relevant Pages

  • Re: Coerce Null to Zero?
    ... IOW, just consider the field at its ... lRes = Val) ... I prefer an empty string to zero as a default value, ...
    (microsoft.public.vb.syntax)
  • RE: How does defined work?
    ... Both Zero "0" and empty string " " are defined values in Perl, ... ||I am posting this query in beginners instead of beginners-cgi because I ... ||How can I make this execute the die statement when userId is missing from ...
    (perl.beginners)
  • Re: Validation Rule
    ... I have checked the fields required porperty to yes and allow zero length ... anyway and I select no and get an action failed dialogue message. ... prevents empty string values from being saved. ...
    (microsoft.public.access.formscoding)
  • Re: Update table with Null data
    ... NOTE that inserting a null into a field or leaving it null is never a good ... an empty string or even the word "Null" allows Access to actually use ... > actually a zero length string. ... > Microsoft Access MVP ...
    (microsoft.public.access.forms)
  • Re: Coerce Null to Zero?
    ... Is there a similar technique for coercing it to Zero with numeric fields? ... lRes = Val) ... I prefer an empty string to zero as a default value, ...
    (microsoft.public.vb.syntax)