Software Development optimize

Create a VB6 Command Button that fires repeatedly

There may be times when you want a VB6 Command Button to fire an event repeatedly, such as when you're performing an operation on multiple files. Learn how to create this kind of button in this VB tip.

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):

  1. Add a Timer Control to the form and set its Interval property to the desired interval between repeated events.
  2. Put the code to be executed repeatedly in the Timer's Timer Event procedure.
  3. Set the Timer's Enabled property to True in the Command Button's MouseDown event procedure.
  4. 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!

0 comments