Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

painting and working 1

Status
Not open for further replies.

Tapeworm

Programmer
Mar 6, 2001
8
DE
I have a picture box in which i start some animations
(lines, text, circles...).

I have a start and stop button, but if I click it the animation always runs til its end.

My Question: How can I run an animation without blocking the actions in my form ?
 
If you are controlling the animation with a loop here is a method i have used to break out of long running loops.

Define a boolean variable (in the declaration section of the form, so it will be visible to all procedures) to signal the animation loop to end.
Code:
Public BreakNow As Boolean
In the cancel button's event procedure, set this variable to true.
Code:
Private Sub cmdCancel_Click() 
BreakNow = True 
End Sub
In the animation loop, insert a DoEvents statement, otherwise the cmdCancel_Click event will not fire because the animation loop is the only code being executed.
Code:
Private Sub cmdAnimate_Click() 

BreakNow = False 

While NotDone 'it doesn't matter what kind of loop

DoEvents 

If BreakNow = True Then 
   GoTo EndAnimation 
End If 

'the rest of your loop here 
Wend 
EndAnimation: 
'clean up after the animation here 
End Sub
Ruairi

Could your manufacturing facility benefit from real time process monitoring? Would you like your employees to be able to see up to the minute goal and actual production?
For innovative, low cost solutions check out my website.
 
Thanx,

the DoEvents - function was what I was looking for...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top