An easy way to get the keyascii for a key is to do something like this:
CODE
Private Sub Form_KeyPress(KeyAscii As Integer)
MsgBox KeyAscii
End Sub
When you press a key on the keyboard, it pops up a messagebox telling you what the keyascii of it is.
I went ahead and found out that the keyascii of the ESC key is 27.
You wanted to know how to clear the textbox and label when you press the ESC key. Well, first, you gotta make sure you're coding into the textbox control. The textbox will have focus, not the form, and so the textbox will get the keypress event, not the form.
Here's a quick alteration that should do what you need:
CODE
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then
Text1.Text = ""
Label1.Caption = ""
End If
End Sub
I could have written "vbKeyEscape" in place of "27", and it would have worked just as well. It's your choice if you wish to write the number or the words. Just make sure it's a real VB constant before you try to use it. A good way is to type it out in all lowercase and see if it capitalizes first.
Examples: vbKeyA, vbKeySpace
You could alternatively use "vbNullString" in the place of the blank quotes, but I figure this way is easier to remember.
Now I wasn't quite sure what you needed for the "result" of the textbox and putting it into the label. Could you clarify on that?
This post has been edited by Zhalix: 3 Jul, 2008 - 02:43 AM