Results 1 to 4 of 4

Thread: reset command

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    reset command

    how to write the code to clear the content inside text box when the button is press.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: reset command

    Code:
    Private Sub Command1_Click()
    Text1.Text = vbNullString
    End Sub

  3. #3
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: reset command

    Properly:
    Code:
    Private Sub Command1_Click()
      Text1.Text = ""
    End Sub
    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.

  4. #4
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: reset command

    have a look at this, I thought it was kind of interesting
    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
    With 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.
    Last edited by Milk; Mar 28th, 2007 at 06:03 PM. Reason: Added link to an article discussing VB strings and their BSTR structure

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width