-
How to use timer in a module
Sorry for my stupid question:
I want to use a time only in a module, I do not want to add the timer control into a form. How can I define the timer in a module in VB6? Can anybody give an example?
Thanks.
Last edited by shuiqq; 11-23-2005 at 03:07 PM.
-
Add this in a bas module:
Code:
Public Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Private Sub TimerProc(ByVal hwnd As Long, _
ByVal lMsg As Long, _
ByVal lTimerID As Long, _
ByVal lTimer As Long)
'' your code here
End Sub
To start the timer:
myTimer = SetTimer(0, 0, millisec, AddressOf TimerProc)
To stop the timer:
KillTimer 0, myTimer
Marco
"There are two ways to write error-free programs. Only the third one works."
Unknown
-
Thank you, Macro.
What are meaning of the parameters in the code? Will the subroutine TimerProc() run in background?
In the function SetTimer(), how can I defined the address of the function TimerProc() in the design time?
Normally I use VB timer control that has few properties in a form, and it is easy to use. Is it possible to use it in a .bas module?
Thank you.
-
VB is strictly single threaded, therefore TimerProc will run in the same thread of the main application, the same way as for the Timer event of the Timer control. For the SetTimer API, look at its defintion in the MSDN documentation (if you do not have MSDN installed, go to www.msdn.com)
Because SetTimer is an API, VB does not have a design interface for it. Sorry, this is coding 'the old way' (or the right way, like someone thinks)
Controls can't be added in a bas module. That is, they need a 'container' (like a form) to be created (or 'hosted'). And events can only be handled in cls, frm or ctl files
Marco
Last edited by mstraf; 11-28-2005 at 08:06 PM.
"There are two ways to write error-free programs. Only the third one works."
Unknown
Similar Threads
-
By teja8100 in forum VB Classic
Replies: 7
Last Post: 05-18-2005, 09:44 AM
-
By jackal in forum ASP.NET
Replies: 3
Last Post: 03-28-2003, 01:29 PM
-
By Tomas in forum ASP.NET
Replies: 0
Last Post: 05-22-2002, 01:10 AM
-
By Ranger in forum VB Classic
Replies: 2
Last Post: 12-08-2000, 08:26 PM
-
By Duncan Atack in forum Web
Replies: 0
Last Post: 07-13-2000, 10:01 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks