Clearing data held in a text box

crazymarvin

Member
Joined
Nov 22, 2006
Messages
18
Location
Belfast, UK
Programming Experience
Beginner
Whats better to use;
VB.NET:
TextBox.Clear
or
VB.NET:
Textbox.Text = ""
I'd allways been taught to use second method, however the text book i was looking at, used the Clear prorpety.
 
They both work the same for clearing the text.

But consider that you have a method that does something and sets the text, sometimes that text is empty. Now you would probably code this method like this:
VB.NET:
Sub something1(ByVal input As String)
    input = input & input
    TextBox1.Text = input
End Sub
The alternative would be ridiculous:
VB.NET:
Sub something2(ByVal input As String)
    input = input & input
    If input = "" Then
        TextBox1.Clear()
    Else
        TextBox1.Text = input
    End If
End Sub
Here are two more ways of resetting the string value of Text property:
VB.NET:
TextBox1.Text = String.Empty
TextBox1.Text = Nothing
 
Back
Top