Sign in to follow this  

vb problem

This topic is 4533 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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
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
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

This topic is 4533 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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