Check Variable

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

Guest

Hi
What is the best way to check if a 'String' variable is null or empty? I was usin

If strValue.Empty Then ..

But I am getting an error.
 
Hi,

Dim s As String

If s Is Nothing Then

MessageBox.Show("Empty String")

End If



Ken
 
Null and Empty are two different things. 'Null' means the String object
hasn't been set to an instance of a String. 'Empty' is a member of the
String class representing the zero-length string "". Try the following...

If Not strValue Is Nothing Then
If strValue Is String.Empty Then
MessageBox("String is empty")
Else
MessageBox("String has a value")
End If
Else
MessageBox("String is null, or Nothing")
End If
 
Hi Ken,

You should be happy that Armin is not here,

In my opinion the explanation from Scott the correct one.

(I do this also for the OP)

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top