Click to See Complete Forum and Search --> : Selecting text in a text box
Gimpster
Nov 8th, 1999, 02:42 AM
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
corneslen@hotmail.com
ICQ# 47799046
QWERTY
Nov 8th, 1999, 02:48 AM
Try this:
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).]
Compwiz
Nov 8th, 1999, 03:01 AM
For easier use, make one single subroutine:
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:
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
tyoung@stny.rr.com
ICQ: 15743470
AIM: TomY10
PERL, JavaScript and VB Programmer
Gimpster
Nov 8th, 1999, 03:04 AM
Thanks, that worked perfectly! Hey, I was just wondering, what is PolComSoft???
------------------
Ryan
corneslen@hotmail.com
ICQ# 47799046
QWERTY
Nov 8th, 1999, 03:06 AM
You will find out soon
------------------
Visual Basic Programmer (at least I want to be one)
------------------
PolComSoft
You will hear a lot about it.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.