Results 1 to 10 of 10

Thread: Increcing Numbers...

  1. #1

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211

    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

  2. #2
    Hyperactive Member mikef's Avatar
    Join Date
    Jun 2000
    Location
    Beach bound...
    Posts
    510
    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!"

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    I don't understand why you couldn't call your sub from the Timer?

  4. #4
    Hyperactive Member mikef's Avatar
    Join Date
    Jun 2000
    Location
    Beach bound...
    Posts
    510
    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!"

  5. #5

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    well here is what i have now

    VB Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2. If KeyCode = 39 Then
    3. Picture2.Left = Picture2.Left + 60
    4. End If
    5. End Sub


    but i wanted it like it you kep holding it it wouldbe like + 61, 62, 63 ,64 ect

  6. #6

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    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

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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:
    1. Private Sub Timer1_Timer()
    2. If Check1.Value = 0 Then
    3.     Picture1.Left = Picture1.Left + 60
    4. Else
    5.     Picture1.Left = Picture1.Left - 60
    6. End If
    7. End Sub
    8.  
    9. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    10. Timer1.Enabled = True
    11. Timer1.Interval = 100
    12. End Sub
    13.  
    14. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    15. Timer1.Enabled = False
    16. End Sub

  8. #8

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    ok but i wanted it to go faster the onger you hold it down

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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

  10. #10
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    Connecticut, USA
    Posts
    308
    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
  •  



Click Here to Expand Forum to Full Width