-
this is my very first program and i don't know that much about vb. anyways.. i have 4 text boxes in a row ( look below 1-4), in the 4th one i have a "0" already in place.
when someone tabs to the box with the zero how do i get it to highlight the zero so when they type in a number into the text box the zero is replaced by what they type ??
right now its default is the user has to hit the delete key to remove the zero and then type it in...
what's the command to replace the 0 when tabed to the textbox?? if i can get it to highlight it, i'll probably add the feature to all the text boxes
| | 1
| | 2
| | 3
| 0| 4
thanks so much for the help..
-
I know there must be a better way to do this, but this is all I can think of right now. (Its been one of those days).
Code:
Private Sub Text4_GotFocus()
Text4.SelStart = 0
Text4.SelLength = 1
End Sub
-
Actually, it's like this:
Code:
Text1.SelLength = Len(Text1.Text)
-
You could also try this everthing is the same except for a change in the SelLength Len(Text4) will get you the length of the text in the box so if it changes the SelLength will change
HTH
Phil
Private Sub Text4_GotFocus()
Text4.SelStart = 0
Text4.SelLength = Len(Text4)
End Sub
-
Or try SendKeys
Code:
Private Sub Text1_GotFocus
SendKeys "{Home} + {End}"
End Sub
-
I tried creating the following sub and placed it in a module:
Code:
Public Sub GotFocus(nControl As Control)
On Error Resume Next
nControl.SelStart = 0
nControl.SelLength = Len(nControl.Text)
End Sub
Then in every control that I want it highlighted when entered I place this in the GotFocus event:
Code:
Private Sub Text1_GotFocus()
GotFocus Me.ActiveControl
End Sub
-
Try this.
I dunno if this is what you're after, but it will select and highlight the first "0" in your text box when it gets the focus:
Code:
Private Sub Text1_GotFocus()
Dim intStartPos As Integer
'Get the first 0 in the text box
intStartPos = InStr(1, Text1.Text, "0")
If intStartPos > 0 Then
'Select it
Text1.SelStart = intStartPos - 1
Text1.SelLength = 1
End If
End Sub
Hope this helps.
Later
REM
-
I think enough people have answered this thread, the first reply was one of the best, but then it evolved into the third reply, which is the best so far(it highlights all the text in a text box).
But I read once in forum feedback where somebody got mad because a question was already answered but it was really easy so people kept replying to it with their own answer, this kind of annoys me too, because since the question was easy, lots of people had to(read: wanted to) answer it, instead of trying to answer the harder questions that nobody is answering.........
my $0.02
PS: I do not mean to offend anyone with my opinion.
PS again: Yours doesnt work QWERTY
-
Hmmm...
Well, the guy asked the following:
[QUOTE]
Originally posted by egiblock
when someone tabs to the box with the zero how do i get it to highlight the zero so when they type in a number into the text box the zero is replaced by what they type ??
[QUOTE]
He didn't ask how to select ALL text. I simply found that no one had specifically addressed his problem, that being how to select only the zero. I only posted because no one else had done this. By no means do i go about 'adding' to threads because i find a solution that has al ready been documented 'easy'. This is not intended to be a harsh comeback to your post Dennis, i'm just stating ther obvious :D
Later
REM
-
Posted specifically to spite Dennis:
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const EM_SETSEL = &HB1
Private Sub Text4_GotFocus()
Call SendMessage(Text1.hWnd, EM_SETSEL, 0, 1)
End Sub
PS egiblock, don't worry about this method of doing it. I just posted this to annoy my :) best friend :) dennis
-
A reply to Dennis:
I think most of us who ask for help are looking for more than just the solution to our coding problem. We also want to learn! Anyone who posts an alternate way of doing something has a legitamate post regardless of how many times the question has been answered. Us newbies choose and use the coding example that we understand best or that best fits our coding style, but we learn from all of them.
Your opinion would be legitamate, though, if someone posted an identical solution after the question had been answered.
I personally appreciate the efforts of all you guys that make this site the storehouse of knowledge that it is.
Keep up the good work! (But, don't stifle anyone!)
Wendy
-
Also to Dennis
Well it works on my machine (vb 6 ent sp4, win 98 se). [sarcastic]Sorry it doesn't work for you [/sarcastic]