09-02-2004, 08:54 AM
I'm trying to create a time object from code only. Here's what I have so far...could someone please tell me what I'm doing wrong? :huh:
Dim tmr1 As Timer
'I need something right
'here b/c I'm getting
'the object variable or
'with block not set msg
tmr1.Interval = 3000
tmr1.Enabled = True
09-02-2004, 08:59 AM
any time you work with objects, you need to SET the object to a new instance...
set tmr1 = new Timer
Yeah, as john said... this wont work. bad assumption on my part. Should have tried it first. API is the way to go when doing this from a module...
you may also want to look into the SetTimer and KillTimer APIs...
Why not use the SetTimer API?
JJ: That won't work.
09-02-2004, 09:10 AM
Ya, I tried the "set yada = new Timer" thing earlier and it didn't like it. Any other ideas? I'll have a look at the api, too.
09-02-2004, 09:53 AM
ah...just tried that with a timer, no good... at least in a module.
quick example using the API
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 Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim m_lCounter As Long
Dim llRetVal As Long
m_lCounter = 0
llRetVal = SetTimer(0, 0, 10000, AddressOf TimerProc)
Do While m_lCounter < 6
KillTimer 0, llRetVal
Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
Debug.Print Format(Now(), "HH:NN:SS AM/PM")
m_lCounter = m_lCounter + 1
09-02-2004, 10:21 AM
OK, thanks fellas. I was fighting with that same example, and now I see what I'm doing wrong. Thanks a million!