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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlighting TextBox while typing.....

Status
Not open for further replies.

rajeshnrh74

Programmer
Jun 19, 2007
9
Hi Gurus,
I need one solution
I'm using VB6, one of its Form contains a TextBox
What i need is whatever characters I type in it that
should be highlighted
ex

First when I type "a" -> "a" should be selected
second when I type "b" -> "ab" should be selected
third when I type "c" -> "abc" should be selected
fourth when I type "d" -> "abcd" should be selected
likewise it go.

ie overall characters upto the cursor end should be selected.

Help me out.
 

Are you sure this is what you want?
First when I type "a" -> "a" should be selected
If the text is selected then the next keystroke will overwrite all selected text.

If not, can you explain exactly what you do want.

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Thnks for your response.
I'll explain clearly
VB6 Form has 1 Textbox
if I type "abc" (without Quotes) in the Texbox the whole word "abc" (without Quotes) should be
highlighted & focus should be in Textbox itself.
 

Rather please explain, why you want to do this, that is, what is the purpose of doing this?

When text is selected, the next key press will/should erase the selected text. That is the purpose of selected text.

As johnwm pointed out, selecting all text which comes after the insertion point would make more sense.
 

Thnks for your response.
Actually my work behind reading Barcode thru Barcode Reader into the
TextBox, The Maxlength of the TextBox is 12.
If I Input some characters manually into the TextBox Say "abc" (without quotes)
now the cursor is in 4th place from there it won't allow Barcode Reader to read.
It should start from 1st place only by erasing already existing 3 characters.
This is my situation.

Can U come out of this.
 
Easy - use SelStart and SelLength. They are both covered in VBHelp

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Johnwm
R U saying
Text1.SelStart =0
Text1.SelLength = Len(Text1.Text)
in Got_Focus Event.

After typing "ABC" (without quotes) the cursor is in 4th place ok. My barcode length is 12 characters.
When I read barcode thru reader it starts from 4th place
& the last three characters of barcode cut off due to max.
length of the Textbox is 12.
What i want is before reading barcode the already existing
Characters "ABC" (without quotes) in the Textbox should be cleared.
 


I would just set up a hidden text box (MaxLength =0) and just have the barcode read into that.
Then in that hidden textbox's change event, check the value and if not empty, then set the Text property of the visible textbox to the value of the hidden one.
 
so if someone types in 10 numbers, and you scan something it just wipes it out? think about that

-David
2006 & 2007 Microsoft Most Valuable Professional (MVP)
2006 Dell Certified System Professional (CSP)
 
If a scanned entry is always 12 characters long and you want a scanned entry to overide any characters already entered then something like;

RequiredScancode = Right$(TextBox.text,12)
'optionally replace any manually entered text so it can be completed
If len(TextBox.text)> 12 then
TextBox.Text = Left$(TextBox.Text,Len(TextBox.Text)-12)
end if

may be of help. You would have to reconsider your current use of TextBox.MaxLength.
 
<What i want is before reading barcode the already existing
Characters "ABC" (without quotes) in the Textbox should be cleared.

Wait a minute! If this is all you want, then put this line in your bar code reading procedure first of all.
Code:
myTextBox.Text = ""
Sounds to me like all you want to do is get rid of any characters that a person typed in before reading in the barcode. Am I wrong?

Now, another idea is to not use a text box in the first place! If no user is ever going to type letters into it, and you don't want to allow a copy and paste facility, then all you need is a label.

Overengineering is an antipattern....

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top