Click to See Complete Forum and Search --> : selecting text in textbox, something different


olemiss
September 17th, 1999, 10:31 PM
Hi everyone,
I am looking for a way to select text in a text box without having to put this

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

into every textbox focus event. I have over a one hundred textboxes. That is a lot. Sure I could put it in a public sub and then call that in every focus event but still the same inherent problem - - 100+ textboxes. whehh. I am looking instead for something that only has to be declared once when the form loads. I am new to this. I guess it would be some kind of API call?
Any help or direction would be great. Thanks

Harold

Mikesc
September 18th, 1999, 09:59 AM
Even if you did use an API call (check the SDK for the text control) you would still have to call it a hundred times. You can set them all nearly at once by iterating through the form's??
controls collection then use a statement like 'If TypeOf cntrl Is Textbox then ' and insert your code you posted here.<==not sure if it would work but trying to give you some ideas...

Mikesc
September 18th, 1999, 10:18 AM
The textbox has to have focus to have its text selected, just tried it out. Doh!

September 18th, 1999, 10:47 AM
write the code(as u mentioned Above) in the gotfocus event and made this an activex control use it anywhere

Ximmer
September 18th, 1999, 02:21 PM
If you make your Textboxes into a Control array (Give all your Textboxes the same name) then you can Select your TB's text like this.

For A = 0 to 99
Text(A).SelStart=1
Text(A).SelLength=5
Next

And That's a WHOLE Lot simpler than doing 100's of those statements... (But you'll have to Rename/Remake your TB's (Textboxes)

-Ximmer

September 18th, 1999, 04:27 PM
Mikesc,

Thanks. Yes, 'If typeof control is textbox' works. Only have to call that function with one line. That is what I had decided to do after I posted. I had contempleated the idea before but thought I would still see if possible another way. However, Ximmer had a great idea bout making all the textboxes a control array. I think that could be useful. 'preciate the help

Harold

Mikesc
September 19th, 1999, 09:54 AM
Sorry about my lapse of judgement yesterday. Ximmer's idea would work but not the code. If you got the textbox array set up, just put your code in the GotFocus event. It'll select the text in any textbox in the array, when, of course, the box enters focus.

Bruno
September 19th, 1999, 11:52 AM
Maybe you can use timer:
http://www.vb2themax.com/Item.asp?PageID=TipBank&ID=82

Good luck!