QUOTE(rabbit_slayer @ 1 Oct, 2007 - 11:40 PM)

ok, i kinda figured out the whole thing, but it doesn't work and i don't understand why...
look:
CODE
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyUp
Text1.Text = "UP"
Case vbKeyDown
Text1.Text = "DOWN"
Case vbKeyLeft
Text1.Text = "LEFT"
Case vbKeyRight
Text1.Text = "RIGHT"
End Select
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyUp
Text1.Text = "neutral"
Case vbKeyDown
Text1.Text = "neutral"
Case vbKeyLeft
Text1.Text = "neutral"
Case vbKeyRight
Text1.Text = "neutral"
End Select
End Sub
Private Sub Timer1_Timer()
cmd1.Top = cmd1.Top - 20
End Sub
Private Sub Timer2_Timer()
cmd1.Top = cmd1.Top + 20
End Sub
Private Sub Timer3_Timer()
cmd1.Left = cmd1.Left - 20
End Sub
Private Sub Timer4_Timer()
cmd1.Top = cmd1.Top + 20
End Sub
Private Sub Timer5_Timer()
If Text1.Text = "UP" Then
Timer1.Enabled = True
If Text1.Text = "DOWN" Then
Timer2.Enabled = True
If Text1.Text = "LEFT" Then
Timer3.Enabled = True
If Text1.Text = "RIGHT" Then
Timer4.Enabled = True
If Text1.Text = "neutral" Then
Timer1.Enabled = False
If Text1.Text = "neutral" Then
Timer2.Enabled = False
If Text1.Text = "neutral" Then
Timer3.Enabled = False
If Text1.Text = "neutral" Then
Timer4.Enabled = False
End If
End If
End If
End If
End If
End If
End If
End If
End Sub
it only works for vbkeyup...left, right and down are not responding!
plz help
Hi, Im no expert but Ive done a couple of simple vbgames where you move around objects with the arrowkeys. I suppose that is what you're trying to do, moving around 'cmd1'. I would write the code like this:
CODE
'A variable for each of the directions
dim vxr as integer, vxl, vyu, vyd
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
'Sets the variables to 20 or -20 when you press the keys
Select Case KeyCode
Case vbKeyUp
vyu = -20
Case vbKeyDown
vyd = 20
Case vbKeyLeft
vxl = -20
Case vbKeyRight
vxr = 20
End Select
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
'Sets the variable to 0 when you release the keys
Select Case KeyCode
Case vbKeyUp
vyu=0
Case vbKeyDown
vyd=0
Case vbKeyLeft
vxl=0
Case vbKeyRight
vxr=0
End Select
End Sub
Private Sub Timer1_Timer()
' One timer who moves it to all directions at the same time,, pressing two buttons ie left and right will make the total change to 0 making it stand still in that direction
cmd1.Top = cmd1.Top + vyu
cmd1.Top = cmd1.Top + vyd
cmd1.left = cmd1.left + vxl
cmd1.left = cmd1.left + vxr
End Sub
I think that should work, here you have one timer which controls all the directions and it's enabled all the time.
I understand that there's probably lots of better ways to write this but Im quite new to programming,, I hope I could help