i am making a program where if you hold down a key the number will get bigger and bigger i tried useing a timer but the numbe increcment is in a diffrent sub
Printable View
i am making a program where if you hold down a key the number will get bigger and bigger i tried useing a timer but the numbe increcment is in a diffrent sub
Try using the Key_Press event and each time that event fires, increment your number.
Code:Private Sub Key_Press()
my number = mynumber+1
End Sub
or
Private Sub Key_Press()
Call MyDifferentSubThatContainsMyIncrementCode
End Sub
I don't understand why you couldn't call your sub from the Timer? :confused:
yeah... me neither.... if he uses the key_press event at least he can drop the timer control.
well here is what i have now
VB Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 39 Then Picture2.Left = Picture2.Left + 60 End If End Sub
but i wanted it like it you kep holding it it wouldbe like + 61, 62, 63 ,64 ect
sorry i didnt even no you could call sub...Quote:
Originally posted by Hack
I don't understand why you couldn't call your sub from the Timer? :confused:
so would this be right
Option Explicit
Dim speed As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 39 Then
Picture2.Left = Picture2.Left + speed
End If
Call Timer1_Timer
End Sub
Private Sub Timer1_Timer()
speed = 60
speed = speed + 1
End Sub
I used this will a simple mouse down, and moved the picture back and forth (after checking the decrement checkbox) with no problem (and I did use a Timer).VB Code:
Private Sub Timer1_Timer() If Check1.Value = 0 Then Picture1.Left = Picture1.Left + 60 Else Picture1.Left = Picture1.Left - 60 End If End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Timer1.Enabled = True Timer1.Interval = 100 End Sub Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Timer1.Enabled = False End Sub
ok but i wanted it to go faster the onger you hold it down
Ok then, instead of hard coding the 60, use a counter that starts with the picture boxe's current .Left position, and have the timer increment the counter as long as the mouse is depressed. Then your code would be Picture1.Left = Picture1.Left + counter
Is this for a game or something?