hello all :)
first of all thanks for this amazing website.
I am a starter in VB, I need your help in a code that end it self when the user type exit.
somebody told me to use vbKey, but it is ok for one key only (as I know)
thank you
regards.
Printable View
hello all :)
first of all thanks for this amazing website.
I am a starter in VB, I need your help in a code that end it self when the user type exit.
somebody told me to use vbKey, but it is ok for one key only (as I know)
thank you
regards.
type where?Quote:
I need your help in a code that end it self when the user type exit.
@fjober
use this in the extbox
Search for the keyascii table for different kinds of keys...Code:Private Sub Text1_KeyPress(KeyAscii as Integer)
If Keyascii = 13 Then
If Text1.Text = "Exit" Then
End
End if
End if
Exit Sub
uggh never use endQuote:
If Text1.Text = "Exit" Then
End
End if
good morning
thanks for replaying, but I may didn't clear what I want.
I don't want the user to type in a text box or any other field
look at this code:
as you know, the last program will end it self on pressing F and there are no fields.Code:Private Sub Form_KeyDown(KeyCode As Integer , Shift As Integer)
if KeyCode = vbKeyF Then End
End Sub
I just want it to end on typing exit instead of F
I think this will give you an idea.... You have to play with it to get the perfect one that really suits you... :wave:
Code:Option Explicit
Dim strTemp As String
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case (KeyCode)
Case vbKeyE: strTemp = strTemp & "E"
Case vbKeyX: strTemp = strTemp & "X"
Case vbKeyI: strTemp = strTemp & "I"
Case vbKeyT: strTemp = strTemp & "T"
End Select
If strTemp = "EXIT" Then Unload Me
End Sub
Private Sub Form_Load()
strTemp = ""
Me.KeyPreview = True
End Sub
oh my god, this code is really good but....
it would work only if user typed EXIT
what if an error happened while typing? "ECIT" instead of "EXIT" (for example), this means that the program will not continue as I want it because the user cannot undo or delete what he typed.
thanks
orCode:Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case (KeyCode)
Case vbKeyE: strTemp = strTemp & "E"
Case vbKeyX: strTemp = strTemp & "X"
Case vbKeyI: strTemp = strTemp & "I"
Case vbKeyT: strTemp = strTemp & "T"
case else: strtemp = ""
End Select
If strTemp = "EXIT" Then Unload Me
select case strtemp ' clear any invalid strings
case "E", "EX", "EXI", EXIT"
case else : strtemp = ""
end select
End Sub
Code:Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
if keycode = vbKeyE and strTemp = "" then strTemp = "E"
if keycade = vbKeyX and strtemp = "E" then strTemp = strTemp & "X"
if keycode = vbKeyI and strtemp = "EX" then strTemp = strTemp & "I"
if keycode = vbKeyT and strTemp = "EXI" then strtemp = strTemp & "T"
If strTemp = "EXIT" Then Unload Me
End Sub
Or:
Code:Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Static n As Long
Select Case KeyCode
Case vbKeyE: n = -(n = 0) * 1
Case vbKeyX: n = -(n = 1) * 2
Case vbKeyI: n = -(n = 2) * 3
Case vbKeyT: If n = 3 Then Unload Me else n = 0
End Select
End Sub
hello everybody
thanks for your help and your ideas
I have wrote a code that do what I want, the most important thing in this code that you can undo what you have typed, here it is:
Code:Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
str = str & Chr(KeyCode)
If LCase(str) = "exit" Then End
If KeyCode = vbKeyZ Then str = ""
End Sub
A suggestion: Rather than using End, you can use Unload Me ... :wave:Quote:
If LCase(str) = "exit" Then End
Check this link: http://www.vbforums.com/showthread.php?t=511766