What's the best way to do this

G

Guest

Hi,
What's the best way to check if two or more textboxes are empty before
executing a task?

I have the foll which is NOT WORKING

If Not (txtDateFrom.Text Is Nothing) And (txtDateTo.Text Is Nothing) Then


.....DO THIS

Else

.....Do that

End If

Thanks
 
M

Mark Rae

If Not (txtDateFrom.Text Is Nothing) And (txtDateTo.Text Is Nothing) Then

If (txtDateFrom.Text <> "") And (txtDateTo.Text <> "") Then

or

If (txtDateFrom.Text <> String.Empty) And (txtDateTo.Text <> String.Empty)
Then
 
J

Jeffrey Palermo [MCP]

Chris,
Mark is correct. testing against Nothing will never be true, but Text
could be an empty string. Use String.Empty rather than "". Using ""
allocates a new string object, but string.Empty uses a global instance of
string that is 0-length. This will save just a little bit of memory.
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top