|
-
June 22nd, 2001, 09:58 AM
#1
Create a timer at runtime
I'm trying to create my own timer class to allow more than 64 seconds.
But I'm trying to do it without Sleep or something similar, so the thing I'm trying to do is to use the normal timer and run it a few times.
so I'm trying to do:
Dim withevents Timer1 as Timer
Works fine, but how the hell do I instanciate this thing? I mean, CreateObject("VB.Timer") doesn't work of course.
Any idea? Now I'm switching to datediff otherwise!
-
June 22nd, 2001, 10:16 AM
#2
Re: Create a timer at runtime
Here is an API timer (without timer)
The SetTimer function creates a timer with the specified time-out value.
'In a module
'-----------
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
'· uElapse - Specifies the time-out value, in milliseconds.
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
debug.print "Time interval"
KillTimer Form1.hwnd, 0
End Sub
'In a form
'--------
Private Sub Form_Load()
'Create an API-timer 1000 msec
SetTimer Me.hwnd, 0, 1000, AddressOf TimerProc
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Kill our API-timer
KillTimer Me.hwnd, 0
End Sub
Iouri Boutchkine
[email protected]
-
June 22nd, 2001, 12:26 PM
#3
Re: Create a timer at runtime
This is excellent, I didn't know there was api timer.. otherwise I wouldn't have wasted my time.
Is there a possible problem of enabling and disabling the timer in the callback function itself?
I mean, I don't want the timer to work when I'm in the callback function, and I wish to start it again when I'm getting out of it.
Thanks!
-
June 22nd, 2001, 01:14 PM
#4
Re: Create a timer at runtime
I never tried this, but in the code you can see how to enable/disable timer from the main proc.
Good luck
Iouri Boutchkine
[email protected]
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
|
Click Here to Expand Forum to Full Width
|