vb problem
My code as below
Dim acc As Integer, cnt As Integer
Private Sub Form_Load()
acc = 0
cnt = 0
End Sub
Private Sub Timer1_Timer()
cnt = cnt + 1
Shape1.Left = Shape1.Left + acc * cnt * cnt / 2
End Sub
Private Sub Form1_KeyDown(keycode As Integer, shift As Integer)
Select Case keycode
Case vbKeyUp
Print acc
If acc < 6 Then
acc = acc + 1
Case vbKeyDown
Print acc
If acc > 0 Then
acc = acc - 1
End Select
End Sub
I want to use UP and DOWN keys to control a Circle to accelerate and deccelerat.
But the code doesn't work.
I don't know what's wrong with it.
The object's move is just ok.
But when I press the UP or DOWN key, the object doesn't accelerate or deccelerate.
But when I press the UP or DOWN key, the object doesn't accelerate or deccelerate.
Does your form have the focus when you press the buttons? Have you checked to make sure that the Key events are actually running by putting a breakpoint in your code and running?
Does your form have any Command buttons, TextBoxes, PictureBoxes, etc? If so, they could keep the focus from the Form, and thus the KeyDown event won't be reached.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement