Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextBox SelLength Problem 1

Status
Not open for further replies.

MaxRaceSoftware

Programmer
Jun 10, 2002
36
US
i'm creating a very simple Form that has 1 TextBox that the user inputs info , then the program calculates data and displays it in Label1.Caption ...but everytime after the user Inputs into TextBox and presses ENTER key , the
TextBox text is not HighLighted/Selected ...you just can't enter data into the TextBox without it being added to end of the previous data .

just discovered a VB6 TextBox SelLength problem that seems common in all versions, even Visual Basic for Dos 1.0

when only using just 1 TextBox and 1 Label on a Form

i can't make the TextBox have selected text with

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

the only way i can make this work is to add another
TextBox --> Text2.Text , and hide it on the Form by making both the Back and Fore Colors the same as the Form
and without a BorderStyle

then while the User is inputting text into Text1 , then presses ENTER key ..i send FOCUS to Text2 , which then immediatetly sends FOCUS back to Text1, which then HIGHLIGHTS or SELECTS the Entire Text like its supposed to

Question= How can i achieve this effect without having to use a hidden Text2 Control ??????

Thanks


MaxRace Software - Larry Meaux
ET_Analyst for DragRacers
Support Israel - Genesis 12:3
 
Shorter version =

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

Won't work with only 1 TextBox (1 Control) on a Form

MaxRace Software - Larry Meaux
ET_Analyst for DragRacers
Support Israel - Genesis 12:3
 
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)

This highlights the all of the text in the textbox and puts the cursor at the end of the text (is that what you're trying to achieve?)

Madlarry
 
If you want to highlight all the text in the textbox when user hits 'Enter', use the KeyPress event and look for the key:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text1.SelStart = 0
Text1.SelLength = Len(Text1.text)
End If
End Sub


BTW I find the use of political or religious propaganda in signatures unprofessional and inappropriate in a technical forum such as this
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Private Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii = vbKeyReturn Then
KeyAscii = 0
Label1.Caption = Text1
Text1.SetFocus '<---Forgot to type in this Line
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If

End Sub
=======================
the above works now , with only 1 TextBox Control

i had it coded like johnwm (Programmer) before , but
at 3:30 am in morning ..was forgetting to
code in ;
Text1.SetFocus '<---Forgot to type in this Line

Thanks madlarry and Johnwm




MaxRace Software - Larry Meaux
ET_Analyst for DragRacers
Support Israel - Genesis 12:3
 
Is it same too!!

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
KeyAscii = 0
Label1.Caption = Text1
Text1.Text = &quot;&quot;
End If
End Sub
 
OR -- Is it same too!!

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
KeyAscii = 0
Label1.Caption = Text1
Clipboard.SetText Text1.Text
Text1.Text = &quot;&quot;
End If
End Sub

so that later we can &quot;PAST&quot; !!
 
this is what i had/tried last night that doesn't work !

Private Sub Text1_GotFocus()

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

End Sub

-----------------------

since i had only 1 TextBox , i thought VB6 would cause Text1
to stay in FOCUS , but it doesn't , without
having to type in ;

Text1.SetFocus in KeyPress event

Thanks everyone MaxRace Software - Larry Meaux
ET_Analyst for DragRacers
Support Israel - Genesis 12:3
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top