A Visual Basic 6 Command Button normally fires one event each time it is clicked. However, you may want to create a button that fires an event repeatedly.
Follow these steps to create a button that fires an event repeatedly as long as it is down (and as long as the user has not released the mouse button):
- Add a Timer Control to the form and set its Interval property to the desired interval between repeated events.
- Put the code to be executed repeatedly in the Timer's Timer Event procedure.
- Set the Timer's Enabled property to True in the Command Button's MouseDown event procedure.
- Set the Timer's Enabled property to False in the Command Button's MouseUp event procedure.
This kind of repeating Command Button can be useful in a variety of programming situations, such as performing an operation on multiple files.
Miss a tip?
Check out the Visual Basic archive, and catch up on the most recent editions of Peter Aitken's column.
Advance your scripting skills to the next level with TechRepublic's free Visual Basic newsletter, delivered each Friday. Automatically sign up today!