
Sending keystrokes to a text box
Quote:
> >I have a textbox which I would like to move the cursor to the left after a
> >character is entered. This is in a simple math application I wrote for my
> >8 year old and I would like to make it as automated as possible.
> >Here is the code I tried with no success:
> >Const BACKSPACE = &H8
> >Private Sub txtAnswer_KeyPress(KeyAscii As Integer)
> > If (KeyAscii < Asc("0") Or KeyAscii > Asc("9")) And KeyAscii <>
> >BACKSPACE Then
> > KeyAscii = 0
> > Beep
> > End If
> >End Sub
> >Private Sub txtAnswer_KeyUp(KeyCode As Integer, Shift As Integer)
> > SendKeys "{LEFT}", True
> >End Sub
> >Note that the textbox only allows numbers and backspace.
> >The sendkeys statement appears to have no effect.
> I think what's happening is the "{Left}" is executing before the
> character appears on the screen. Try putting the SendKeys statement
> in the txtAnswer_Change event instead, which doesn't fire until the
> character physically appears on the screen.
> Lee Weiner
> "The difference between a wise man and a fool
> is that the fool never learns from his mistakes."
This is so simple you will kick yourself. Just place the following code
in the text box change event.
Text1.SelStart = 0
I have tried it and it works fine.
Anthony
--
================================================
Artificial Intelligence / Computer Science
The University of Birmingham, England
================================================