Link to home
Start Free TrialLog in
Avatar of tWiZtEr_RX
tWiZtEr_RX

asked on

PRB: TextBox not recognizing KeyAscii 13

this is so weird, i have the exact same code in 2 projects, and in one, when u press enter in the textbox, the text_KeyPress KeyAscii is triggered with ascii value being 13, and in the other project, pressing Enter does absolutely nothing!
This is the code.: In project 1: Works!

Private Sub txtSend_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 38 Then
If dacurrentIndex >= iCounter Then
Exit Sub
End If
dacurrentIndex = dacurrentIndex + 1
txtSend.Text = s_MsgRecall(iCounter - dacurrentIndex)
txtSend.SelStart = Len(txt) + 1
SendKeys "{DEL}"
End If
If KeyCode = 40 Then
If dacurrentIndex <= 0 Then
Exit Sub
End If
dacurrentIndex = dacurrentIndex - 1
txtSend.Text = s_MsgRecall(iCounter - dacurrentIndex) & Space(1)
txtSend.SelStart = Len(txt) + 1
SendKeys "{BS}"
End If
'38 = up
'40 = down
End Sub

Private Sub txtSend_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    If txtSend = "" Then
        Exit Sub
    End If
    SendKeys Chr(8)
    Call cmdSend_Click
End If
End Sub

-----------
This code is in Proj. 2, DOESNT WORK WHEN ENTER IS PRESSED.
I put this line of code in the KeyDown and KeyPress events to see if they are even called and this is the code i put in: "MsgBox KeyCode", and "MsgBox KeyAscii" respectivly. It doesnt even call the messagebox. (i put breakpoints and both KeyDown or KeyAscii werent called)
-
I even put the KeyPreview on both Forms to True and False, it worked on Project 1 with both boolean values. and nothing on Project 2.
I am stumped!
Avatar of GPrentice00
GPrentice00

in project two, do the keydown and keypress events fire for other keys?  Did you copy the code inside the events into the project2 events, or did you copy the whole code from the Private Sub...End Sub?  I've done that before for simplicity, but had misspelled my control name in the new project, and thus TxtGeneSeq_events in my code were never going to be fired for the TxtGenSeq textbox...

Avatar of tWiZtEr_RX

ASKER

Ya, KeyDown and KeyPress are triggered by other keys, even Control+Enter, (with KeyCode, it tells me that Control was pressed, then the next message box is 13(or enter),) but under no other situations (that i have found yet) can the event be triggered by Enter. And for sure hasnt been able to be triggered on its own (just pressing Enter).
and no, this is a Server and Client Project, so i didnt copy the hole code. But the textbox control was copied from the Project1(Client, the one that works), so it has same properties, and the same code is on the txtSend_KeyPress and txtSend_KeyDown because they are both called txtSend in both Projects. im so stumped.
ASKER CERTIFIED SOLUTION
Avatar of AzraSound
AzraSound
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i will quadruple check
THANKS SO MUCH, i expanded my form becuze i had some out of sight, and one that i copied from another program was set to Default=True!
Thanks - cant believe i overlooked the ones i couldnt see (lol :P)
-- danke schon AzraSound
Glad I could help  :-)