vb problem

Started by
6 comments, last by Argoran 18 years, 9 months ago
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.
Advertisement
How does it not work ?

The object is not moving ?
I teleported home one night; With Ron and Sid and Meg; Ron stole Meggie's heart away; And I got Sydney's leg. <> I'm blogging, emo style
The object's move is just ok.
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?
Turring Machines are better than C++ any day ^_~
Exactly. Is it actually working?
The best thing to do is just choose whatever you think you'd prefer, and go for it. -Promit
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.
Form has some lines, a circle and a timer.
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.

This topic is closed to new replies.

Advertisement