Hello,
What I have is a userform with a number of command buttons and a label. Whenever the user moves the mouse over one of the buttons, the caption of the label is updated to display a description of that button's function. This is done in an "animated" fashion, generating the caption one character at a time, using the following code:
Dim intActiveButton as integer
Private Sub cmdButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If intActiveButton <> 1 Then
intActiveButton = 1
Call AnimateText
End If
End Sub
Private Sub cmdButton2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If intActiveButton <> 2 Then
intActiveButton = 2
Call AnimateText
End If
End Sub
Private Sub AnimateText()
Dim i As Integer
Dim sngTimer As Single
Dim strMessage As String
'Retrieve appropriate description string from array
strMessage = gstrDescriptions(intActiveButton)
'Generate description on screen
For i = 1 To Len(strMessage)
Me.lblDescription.Caption = Left(strMessage, i)
sngTimer = Timer + 0.01
Do While sngTimer > Timer
DoEvents
Loop
Next i
End Sub
The problem with this code is revealed when the user moves the mouse over a button while the description for another button is still being generated on screen. Because of the DoEvents statement, the MouseMove event for the second button will fire, and the AnimateText routine will start showing the corresponding description instead. So far, so good. However, once this second instance of the AnimateText routine has run its course, the original instance, which was interrupted by the MouseMove event, is resumed.
To illustrate:
Say there are three buttons, with as descriptions "first", "second" and "third":
f (
mouse over button 1)
fi
fir
s (
mouse over button 2)
se
sec
seco
t (
mouse over button 3)
th
thi
thir
third
secon (
this is where it goes wrong)
second
firs
first
The question: Is there a way to abort the execution of a subroutine when a new event is triggered, rather than merely suspending it?
Thanks in advance for any advice!
Kind regards,
nymm
Bookmarks