The Presents of Null values/Nothing/"" or not

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to check for the presents of null values or null value not being
present. My sample code below:


If EmailAddresses Is Nothing Then

SendMailMessage(EmailAddresses, AlertTitle,
ViolationBody)
End If


The above code works when checking for the presents of a null
value/Nothing/"".
However, I want to check for null not being present ie.



If EmailAddresses not Nothing Then

SendMailMessage(EmailAddresses, AlertTitle,
ViolationBody)
End If

The above code will not compile.

Basically I want to know when nulls are present and not present.

Thanks
 
I tried your example below and the results are the same. It executes the
send when the value of EmailAddresses is a null value (string) or not null
value which means it contains an email address.

Could I be missing something here. If there is no email address then no
need to send mail.

Thanks
 
You didn't mention EmailAddresses was a string in your first post (or
probably I half read it :)). I assumed it was an object (which is why you
were testing for nothing). To test whether a string is empty ("") or not,
you should use this:

If EmailAddresses.Length > 0 Then
' Its a non-empty string
SendMailMessage(EmailAddresses, AlertTitle, ViolationBody)
End If


hope that helps..
Imran.
 
Larry Bird said:
Basically I want to know when nulls are present and not present.

Depends on how you define 'null' for strings...

\\\
If _
Not EmailAddresses Is Nothing AndAlso _
EmailAddresses.Length > 0 _
Then
...
End If
///
 
Larry,

Because everybody does something than me as well

Dim EmailAddress as string is
EmailAdress Is Nothing

Dim EmailAddress as string = "" is
EmailAdress.lenght = 0

Both work with
If EmailAdress = Nothing

I hope this helps?

Cor
 
What you've got is overkill and not needed to check a string for null, just
check for "".
 
That worked great thank for the help


Imran Koradia said:
You didn't mention EmailAddresses was a string in your first post (or
probably I half read it :)). I assumed it was an object (which is why you
were testing for nothing). To test whether a string is empty ("") or not,
you should use this:

If EmailAddresses.Length > 0 Then
' Its a non-empty string
SendMailMessage(EmailAddresses, AlertTitle, ViolationBody)
End If


hope that helps..
Imran.
 
Back
Top