|
-
Jun 27th, 2002, 12:36 PM
#1
Thread Starter
Frenzied Member
Increcing Numbers...
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
-
Jun 27th, 2002, 12:39 PM
#2
Hyperactive Member
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
Last edited by mikef; Jun 27th, 2002 at 12:46 PM.
"If I had known it was going to be that kinda party, I would have stuck my disk in the mash potatos!"
-
Jun 27th, 2002, 12:48 PM
#3
I don't understand why you couldn't call your sub from the Timer?
-
Jun 27th, 2002, 12:51 PM
#4
Hyperactive Member
yeah... me neither.... if he uses the key_press event at least he can drop the timer control.
"If I had known it was going to be that kinda party, I would have stuck my disk in the mash potatos!"
-
Jun 27th, 2002, 12:51 PM
#5
Thread Starter
Frenzied Member
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
-
Jun 27th, 2002, 12:58 PM
#6
Thread Starter
Frenzied Member
Originally posted by Hack
I don't understand why you couldn't call your sub from the Timer?
sorry i didnt even no you could call sub...
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
-
Jun 27th, 2002, 12:58 PM
#7
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
-
Jun 27th, 2002, 10:14 PM
#8
Thread Starter
Frenzied Member
ok but i wanted it to go faster the onger you hold it down
-
Jun 28th, 2002, 06:15 AM
#9
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
-
Jun 28th, 2002, 06:34 AM
#10
Hyperactive Member
Is this for a game or something?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|