-
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
-
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
:):):)
-
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. ;)
-
Just make sure to include the DoEvent or else ur program will freeze!
-
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
-
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...