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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Destroy a timer control

Status
Not open for further replies.

AKarim

Technical User
Mar 20, 2000
41
EU
Hi all,<br>I'm making an application using a timer. When closing my main form (Unload Form1), the timer do not stop and destroy, but goes up to the timeout, then generates an error because the timer's code can't be done<br><br>What is the command to stop and destroy the timer control ?<br><br>Thanks forany help !
 
Timer1.Enabled = False<br><br>will turn off your timer control<br><br>If you created your Timer by dragging the control onto the form - this is all you need to do (all I do anyway)<br><br>If you have a control array of timers create at run-time that you access like this<br><br>Timer1(2).Interval = (some value)<br><br>Then these are separate controls and you must Enable=False for each of them.<br><br>Mike <p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Hi Mike,<br>Yes I did do the Enabled = False, but the timer still go on a last time before ending, causing an error ! <br>Here is my code :<br><br>Private Sub Form_Unload(Cancel As Integer)<br>&nbsp;&nbsp;&nbsp;&nbsp;'Enleve l'icône du tray<br>&nbsp;&nbsp;&nbsp;&nbsp;SystemTray1.Action = 2<br>&nbsp;&nbsp;&nbsp;&nbsp;Timer1.Enabled = False<br>&nbsp;&nbsp;&nbsp;&nbsp;Unload RefreshTimer<br>End Sub<br><br>Private Sub Timer1_Timer()<br>&nbsp;&nbsp;&nbsp;&nbsp;'MAJ des donnees<br>&nbsp;&nbsp;&nbsp;&nbsp;Sleep CInt(Timer1.Tag) '* 60) 'Convertion en minutes<br><b>&nbsp;&nbsp;&nbsp;&nbsp;CRViewer1.Refresh</b><br>End Sub<br><br>the bold line is where it stops, because the CRViewer1 is all ready closed.<br><br>OKOKOKOKOKOKOOKOKOKOKOKOKOKO I now understand<br><br>It is the <b>sleep</b> that I must stop !<br>Probably you know how do I stop it ?<br>Thanks 4 help.<br><br>
 
Akarim,<br><br>Could I suggest that you don't call Sleep from within a timer? You might like to consider using the timer's Interval property which is used to wake up the timer every so often, like this.<br><br>Sub Form_Load<br><br>&nbsp;&nbsp;Timer1.Interval=1000<br>&nbsp;&nbsp;Timer1.Enabled=True<br><br>End Sub<br><br>Sub Timer1_Timer()<br><br>Static Counter As Long<br><br>&nbsp;&nbsp;Counter=Counter+1<br><br>&nbsp;&nbsp;If Counter &gt; 3600 Then<br>&nbsp;&nbsp;Begin<br>&nbsp;&nbsp;&nbsp;&nbsp;'MAJ des donnees<br>&nbsp;&nbsp;&nbsp;&nbsp;Counter=0<br>&nbsp;&nbsp;&nbsp;&nbsp;CRViewer1.Refresh<br>&nbsp;&nbsp;End If<br><br>End Sub<br><br>You need to do the Counter business because there's a maximum of 65,000 or so to the interval property (about a minute)<br><br>Regards<br><br>Mike <p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Yes thanks a lot Mike,<br>How didn't I think about this before ????<br>Any way it's fine now, thanks again<br>Karim AUMJAUD.
 
A pleasure Karim - see you again<br><br>Mike <p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top