Very basic Null value question (1 Viewer)

BlueIshDan

☠
Local time
Today, 12:35
Joined
May 15, 2014
Messages
1,122
Code:
Public Function ValidString(str) As Boolean
       ValidString = (Len(str + vbNullString) > 0)
End Function

parameter str has value = Null

why is Len(str + vbNullString) returning Null
I've used this method for a while now and I've never had issues with Null until now...

This produceses runtime error 92.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:35
Joined
Aug 30, 2003
Messages
36,125
Have you tried "&" instead of "+"? "+" propagates Nulls, "&" does not.
 

pr2-eugin

Super Moderator
Local time
Today, 16:35
Joined
Nov 30, 2011
Messages
8,494
& is used for concatenation + is used for Null propagation. So,
Code:
Null & vbNullString = vbNullString
Null + vbNullString = Null
That is why you get the error.
 

BlueIshDan

☠
Local time
Today, 12:35
Joined
May 15, 2014
Messages
1,122
Omf that's it. I've been working in python and javascript a lot recently lol. I can't believe that slipped my mind! Thank you so much pbaldy and paul :D
 

pr2-eugin

Super Moderator
Local time
Today, 16:35
Joined
Nov 30, 2011
Messages
8,494
The Paul's are happy to help :D Good luck !
 

Brianwarnock

Retired
Local time
Today, 16:35
Joined
Jun 2, 2003
Messages
12,701
Oh dear Paul it's a good job col doesn't read the techie stuff, what's with the ' , is your other job a grocer? :D

Brian
 

Users who are viewing this thread

Top Bottom