Ineluki
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:
Option Explicit
Dim tmr1 As Timer
Sub main()
'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
End Sub
Sub tmr1_timer()
MsgBox "hello"
End Sub
Thanks!!
jjStinger72
09-02-2004, 08:59 AM
any time you work with objects, you need to SET the object to a new instance...
[vb ]
set tmr1 = new Timer
[/vb ]
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.
Ineluki
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.
Thanks
jjStinger72
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
Option Explicit
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
Sub main()
Dim llRetVal As Long
m_lCounter = 0
llRetVal = SetTimer(0, 0, 10000, AddressOf TimerProc)
Do While m_lCounter < 6
DoEvents
Sleep 0
Loop
KillTimer 0, llRetVal
End Sub
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
End Sub
Ineluki
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!