Sign in to follow this  
Argoran

vb problem

Recommended Posts

Argoran    122
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.

Share this post


Link to post
Share on other sites
intrest86    742
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?

Share this post


Link to post
Share on other sites
Mattman    336
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.

Share this post


Link to post
Share on other sites
Argoran    122
I made a mistake here:

"Private Sub Form1_KeyDown(keycode As Integer, shift As Integer)"

It should be:

"Private Sub Form_KeyDown(keycode As Integer, shift As Integer)"

Thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this