I copied your exact code and I could not reproduce the problem. Is there any other code going on in your program that could cause it? Any timers?
You should not have to do this, but you can try explicitly stating "if not bFlag Then Exit Do" right after the Do While bFlag line.
But start a new VB project, and paste this code in there and run it (add a Command1 button to your form).
This will help determine if it's something else in your code or not.
Code:Option Explicit Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Dim bFlag As Boolean Private Sub StartAnimation() bFlag = True Do While bFlag 'Do Animation DoEvents Sleep 10 'update every 10 milliseconds Loop End Sub Private Sub StopAnimation() bFlag = False End Sub Private Sub Command1_Click() Me.Caption = "Animating" StartAnimation End Sub Private Sub Form_Unload(Cancel As Integer) StopAnimation End Sub




Reply With Quote