i have a timer but i dont know how to make that when the timer make 5 sec to call a function
Printable View
i have a timer but i dont know how to make that when the timer make 5 sec to call a function
Code:Option Explicit
Private Sub Form_Load()
With Timer1
.Interval = 5000
.Enabled = True
End With
End Sub
Private Sub Timer1_Timer()
mySub
'remove this if you want to call
'"mySub" constantly every 5 secons
Timer1.Enabled = False
End Sub
Private Sub mySub()
'...
End Sub
hmm i doesn't work for me !! or i didn't understand this part :
vb Code:
Private Sub Timer1_Timer() mySub 'remove this if you want to call '"mySub" constantly every 5 secons
That's the actual call. It's an example. If you remove the line the comment is talking about ('Timer1.Enabled = False'), Timer will fire EVERY 5 seconds - not just once - until it's disabled.
Perhaps you think it doesn't work for you, cause 'mySub' is empty. Try it like this:Code:Private Sub mySub()
MsgBox "Can you see me?"
End Sub
Ok, once you place a timer in the application and look at the properties you should see a property call Interval
The interval propery is in miliseconds, if you want the timer to get triggred every 5 seconds you would set it to 5000. Or code it in the form load.
You should also see an Enable property, that property should be false
VB Code:
Private Sub Form_Load() Timer1.Interval = 5000 'This is the intervals between triggers (5 Seconds * 1000 miliseconds) Timer1.Enabled = True End Sub Private Sub Timer1_Timer() 'Any code that goes in here will get executed 'On the intervals you set before MsgBox "5 seconds Passed" End Sub