Results 1 to 6 of 6

Thread: How to loop through code will holding button?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Hi,

    I want to be able to hold a command button down and have it loop through the click event code so the user can easily scroll through the records..

    For example, the code behind the Command1_Click is:

    Code:
        '-- navigate selected items
        Select Case Index
            Case 0: 'move backward
                If x = 0 Then Exit Sub
                x = x - 1
                PopulateItem x
            Case 1: 'move forward
                If x + 1 = nCnt Then Exit Sub
                x = x + 1
                PopulateItem x
        End Select
    I would want to be able to hold the button down and have it loop through the above code..

    Thanks,

    Dan

  2. #2
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Question

    Imnot exactly sure what u mean, but u should be able to stick in a do while event in there or something and let it terminate after the user lets the button go.

    ?

    I dont know if that helped at all
    Im just sitting in my computer class and the teacher is boring, so im puting up useless posts

    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  3. #3
    Guest

    Talking

    Try this. its a simple example..

    Code:
    Private mbStop As Boolean
    
    Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
      Do
        Label1.Caption = Int(Label1.Caption) + 1
        If mbStop = True Then
          mbStop = False
          Exit Do
        End If
        DoEvents
      Loop
    
    End Sub
    
    Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
      mbStop = True
    
    End Sub
    
    Private Sub Form_Load()
    
      mbStop = False
    
    End Sub
    If you want to use your key's use the key events instead.

  4. #4
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Talking

    Just make sure to include the DoEvent or else ur program will freeze!

    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    kayoca,

    Thanks for the code.. Works great but I would like to expand on your code a little..

    I would like to add 2 things which I don't know how to do..

    1) Put some sort of delay in the loop so that I can control the speed of the loop.. It scrolls way to fast as it is.. I would like to be able to change the value of the delay so I can play around with the speed of the loop.

    2) I don't want the looping action to occur right away. I would like there to be about a 1 or 2 second delay so that if the user just "clicks" the button, it only increments 1 at a time.. But, if the user holds the button for more than a second, the looping action occurs..

    Any ideas?

    thanks,

    Dan

  6. #6
    Addicted Member
    Join Date
    May 1999
    Posts
    161
    For the advance step by step, I would use the Click event as you would normally. As far as delaying or make the speed progressively increase, I would just use a timer.

    The MouseDown would enable the timer and the MouseUp would disable it. Use an integer (or long) to keep track of how many times the Timer event fired. Based on that value, you can vary the the Interval of your timer.

    I never tried that but it should work.... let me know...

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