CodeItBetter Programming Another VB Programming Blog

How to use Timer without using timer control

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'Controls - How to use Timer without using timer control
' Declarations
Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, _
    ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Private mlngTimerID As Long
 
' Module code
Public Sub StartTimer(lngInterval As Long)
    mlngTimerID = SetTimer(0, 0, lngInterval, AddressOf TimerCallBack)
End Sub
 
Public Sub TimerCallBack(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, _
    ByVal dwTime As Long)
    'Do Something Here
Range("A1").Value = Format$(Now, "HH:mm:ss")
End Sub
 
Public Sub StopTimer()
    KillTimer 0, mlngTimerID
End Sub
 
'How can I call this function:
'Call StartTimer(1000)'To start the timer [1000 = 1 second]
'call StopTimer'To stop the timer

Related posts:

  1. How to allow timer function without timer control
  2. How to create a self Closing Message Box
  3. How to use timer control for more than 65,535 milliseconds
  4. How to show/hide a label control at a particular interval using timer
  5. How to stretch image in a Picture Box Control
  6. How to make a beep program, in Visual Basic.. With Timer Settings!
  7. How to Make a Text Box Resizeable
  8. How to Display the Cursor’s coordinates of a Rich Text Box
  9. How to window caption to flash repeatedly
  10. How to visually click Command button through code

Filed under: Controls Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.