What's the best way to do this

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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.
 
Chris, You would use = Nothing to test whether your variable is an instance
of an object. For instance, You could use txtMine = Nothing to see if that
variable was null (Nothing) or if it is an instance of TextBox.

--
Best regards,
Jeffrey Palermo
Blog: http://dotnetjunkies.com/weblog/jpalermo
 
Back
Top