Jump to content
  • Advertisement
Sign in to follow this  
Argoran

vb problem

This topic is 4750 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
Advertisement
The object's move is just ok.
But when I press the UP or DOWN key, the object doesn't accelerate or deccelerate.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!