• Is this the same as NZ() ?

    From Ron Paii@21:1/5 to internet...@foobox.com on Mon Sep 14 05:09:56 2020
    On Monday, September 14, 2020 at 6:18:29 AM UTC-5, internet...@foobox.com wrote:
    I am looking at another person's code. In fact I have to amend it!!

    There is a line that I would not write and am wondering exactly what it means:

    If ctl.Value & "" = "" Then

    Is it the same as

    If nz(ctl.Value,"") = "" then ?

    If not, how does it differ?

    Jim

    ctl.Value & "" will return vbnullstring if ctl.Value is null because string concatenation does not error on null.

    nz(ctl.Value, "") will return vbnullstring if ctl.Value is null because you explicitly called it out.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From internet.shopping@foobox.com@21:1/5 to All on Mon Sep 14 04:18:25 2020
    I am looking at another person's code. In fact I have to amend it!!

    There is a line that I would not write and am wondering exactly what it means:

    If ctl.Value & "" = "" Then

    Is it the same as

    If nz(ctl.Value,"") = "" then ?

    If not, how does it differ?

    Jim

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From internet.shopping@foobox.com@21:1/5 to Ron Paii on Mon Sep 14 05:37:02 2020
    On Monday, 14 September 2020 13:10:01 UTC+1, Ron Paii wrote:
    On Monday, September 14, 2020 at 6:18:29 AM UTC-5, internet...@foobox.com wrote:
    I am looking at another person's code. In fact I have to amend it!!

    There is a line that I would not write and am wondering exactly what it means:

    If ctl.Value & "" = "" Then

    Is it the same as

    If nz(ctl.Value,"") = "" then ?

    If not, how does it differ?

    Jim

    ctl.Value & "" will return vbnullstring if ctl.Value is null because string concatenation does not error on null.

    nz(ctl.Value, "") will return vbnullstring if ctl.Value is null because you explicitly called it out.

    If I understand you correctly, they each result in the same value.

    I will therefore stick with nz(), which to my mind is clearer. It does not rely on knowing the behaviour of string concatenation under these circumstances.

    I hate 'tidying' up someone else's code when I am not sure that I am not altering the behaviour

    Jim

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ron Paii@21:1/5 to internet...@foobox.com on Mon Sep 14 05:56:36 2020
    On Monday, September 14, 2020 at 7:37:09 AM UTC-5, internet...@foobox.com wrote:
    On Monday, 14 September 2020 13:10:01 UTC+1, Ron Paii wrote:
    On Monday, September 14, 2020 at 6:18:29 AM UTC-5, internet...@foobox.com wrote:
    I am looking at another person's code. In fact I have to amend it!!

    There is a line that I would not write and am wondering exactly what it means:

    If ctl.Value & "" = "" Then

    Is it the same as

    If nz(ctl.Value,"") = "" then ?

    If not, how does it differ?

    Jim

    ctl.Value & "" will return vbnullstring if ctl.Value is null because string concatenation does not error on null.

    nz(ctl.Value, "") will return vbnullstring if ctl.Value is null because you explicitly called it out.
    If I understand you correctly, they each result in the same value.

    I will therefore stick with nz(), which to my mind is clearer. It does not rely on knowing the behaviour of string concatenation under these circumstances.

    I hate 'tidying' up someone else's code when I am not sure that I am not altering the behaviour

    Jim

    Because I have learned to NOT to trust VBA automatic type conversion, I would do.

    if cstr(nz(ctl.value, vbnullstring) = vbnullstring then

    if you want to handle user entering a space or 2.

    if trim$(nz(ctl.value,vbnullstring)) = vbnullstring then

    Which WILL change the behavior.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)