how to write the code to clear the content inside text box when the button is press.
Printable View
how to write the code to clear the content inside text box when the button is press.
Code:Private Sub Command1_Click()
Text1.Text = vbNullString
End Sub
Properly:
Although Hack's code works, vbNullString is not the same as a zero-length string. That's directly from MSDN, which also states that vbNullString is used for calling external processes.Code:Private Sub Command1_Click()
Text1.Text = ""
End Sub
have a look at this, I thought it was kind of interestingWith a VB string the only way to clear the BSTR is with vbNullstring, but the Text property also clears the BSTR with "" and vbnullchar. By clear I mean makes the string variable point to a null structure.Code:Private Sub form_Click()
Dim S As String
Debug.Print vbNewLine & "StrPtr with a VB string"
S = " ": Debug.Print """ "" ="; StrPtr(S)
S = "": Debug.Print """"" ="; StrPtr(S)
S = vbNullChar: Debug.Print "vbNullChar ="; StrPtr(S)
S = vbNullString: Debug.Print "vbNullString ="; StrPtr(S)
Debug.Print vbNewLine & "Now StrPtr for a textbox"
Text1.Text = " ": Debug.Print """ "" ="; StrPtr(Text1.Text)
Text1.Text = "": Debug.Print """"" ="; StrPtr(Text1.Text)
Text1.Text = vbNullChar: Debug.Print "vbNullChar ="; StrPtr(Text1.Text)
Text1.Text = vbNullString: Debug.Print "vbNullString ="; StrPtr(Text1.Text)
End Sub