Hi,
what is the code for a program like this
IF Up key is pressed then display hello msgbox
Once up key is not pressed down anymore close hello msgbox and display goodbye msgbox
Thanks much appreciated
Printable View
Hi,
what is the code for a program like this
IF Up key is pressed then display hello msgbox
Once up key is not pressed down anymore close hello msgbox and display goodbye msgbox
Thanks much appreciated
Code:Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
MsgBox ("hello")
End Sub
Code:Private Sub Form_KeyUp(KeyAscii As Integer)
MsgBox ("hello")
End Sub
Quote:
Originally Posted by airman00
Code:Option Explicit
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 38 Then Print "You pressed the UP key."
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 38 Then Print "You released the UP key."
End Sub
Private Sub Form_Load()
Me.Show
Me.KeyPreview = True
End Sub
I considered using a MsgBox, but they are Modal. Because of this your KeyUp code will never execute.Quote:
Originally Posted by Dungeon Keeper
This works for me :)
Edit: shi* i messed the code in post a little, my mistake :DCode:Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
MsgBox ("UP")
End Sub
I fixed it now :D
I didn't mean as a stand alone code block. What you posted first executes the KeyDown event which fires a MsgBox. The MsgBox has to be cleared before any subsequent code will execute. By then the KeyUp event has long past.Quote:
Originally Posted by Dungeon Keeper
You have the same message in both KeyDown & KeyUp events. Change the KeyUp message and you will understand what I'm saying, as it will never fire.
You are aware that you have the ability to edit your posts and your code? It's a better choice than leaving errors posted.:cool:Quote:
Originally Posted by Dungeon Keeper