|
-
Feb 8th, 2010, 02:59 AM
#1
Thread Starter
Addicted Member
[RESOLVED] vbKey help
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.
-
Feb 8th, 2010, 03:17 AM
#2
Re: vbKey help
I need your help in a code that end it self when the user type exit.
type where?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 8th, 2010, 03:25 AM
#3
Re: vbKey help
@fjober
use this in the extbox
Code:
Private Sub Text1_KeyPress(KeyAscii as Integer)
If Keyascii = 13 Then
If Text1.Text = "Exit" Then
End
End if
End if
Exit Sub
Search for the keyascii table for different kinds of keys...
Manny Pacquiao once posted in his twitter:
It doesn't matter if the grammar is wrong, what matter is that you get the message
-
Feb 8th, 2010, 03:34 AM
#4
Re: vbKey help
If Text1.Text = "Exit" Then
End
End if
uggh never use end
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 8th, 2010, 06:15 AM
#5
Thread Starter
Addicted Member
Re: vbKey help
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:
Code:
Private Sub Form_KeyDown(KeyCode As Integer , Shift As Integer)
if KeyCode = vbKeyF Then End
End Sub
as you know, the last program will end it self on pressing F and there are no fields.
I just want it to end on typing exit instead of F
-
Feb 8th, 2010, 08:06 AM
#6
Re: vbKey help
I think this will give you an idea.... You have to play with it to get the perfect one that really suits you... 
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
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Feb 9th, 2010, 05:39 AM
#7
Thread Starter
Addicted Member
Re: vbKey help
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
-
Feb 9th, 2010, 05:52 AM
#8
Re: vbKey help
Code:
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
or
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 9th, 2010, 06:34 AM
#9
Re: vbKey help
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
-
Feb 10th, 2010, 04:10 PM
#10
Thread Starter
Addicted Member
Re: vbKey help
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
-
Feb 10th, 2010, 08:58 PM
#11
Re: vbKey help
If LCase(str) = "exit" Then End
A suggestion: Rather than using End, you can use Unload Me ... 
Check this link: http://www.vbforums.com/showthread.php?t=511766
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|