Results 1 to 5 of 5

Thread: Selecting text in a text box

  1. #1

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    I have a text box which contains some text that is purely to help clarify what the box is for. It is meant to be replaced by the user, and so what I would like to do is have text be selected so that the user can just start typing and it will automatically replace that text. How can I do this?

    ------------------
    Ryan
    [email protected]
    ICQ# 47799046

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    Try this:
    Code:
    Private Sub Text1_GotFocus()
        Text1.SelStart = 0
        Text1.SelLength = Len(Text1.Text)
    End Sub
    ------------------
    Visual Basic Programmer (at least I want to be one)
    ------------------
    PolComSoft
    You will hear a lot about it.

    [This message has been edited by QWERTY (edited 11-08-1999).]

  3. #3
    Hyperactive Member
    Join Date
    Jul 1999
    Location
    NY, USA
    Posts
    270

    Post

    For easier use, make one single subroutine:

    Code:
    Sub txtSelectAll(txtBox As TextBox)
        With txtBox
            .SelStart = 0
            .SelLength = Len(txtBox.Text)
        End With
    End Sub
    and place txtSelectAll Screen.ActiveControl in each text boxes GotFocus event. For example:

    Code:
    Private Sub Text1_GotFocus()
         txtSelectAll Screen.ActiveControl
    End Sub
    
    Private Sub Text2_GotFocus()
         txtSelectAll Screen.ActiveControl
    End Sub
    After a while, you will get sick of writing:

    Text1.SelStart = 0
    Text1.SelLength = Len(Text1.Text)


    in each text box, and then have to change Text1 to Text2 and etc. The code I have provided will save you time, but please note this will only work with text boxes.

    ------------------
    Tom Young, 14 Year Old
    [email protected]
    ICQ: 15743470
    AIM: TomY10
    PERL, JavaScript and VB Programmer

  4. #4

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Thanks, that worked perfectly! Hey, I was just wondering, what is PolComSoft???

    ------------------
    Ryan
    [email protected]
    ICQ# 47799046

  5. #5
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    You will find out soon

    ------------------
    Visual Basic Programmer (at least I want to be one)
    ------------------
    PolComSoft
    You will hear a lot about it.


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