 |

09-02-2004, 08:54 AM
|
 |
Centurion
|
|
Join Date: Apr 2004
Location: Missouri
Posts: 145
|
|
Create Timer From Code
|
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?
Code:
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!!
|
__________________
"Before insulting a man, walk a mile in his shoes. That way, he's a mile away and without shoes."
"Convivially returning with himself, Again he raised the jug up to the light;
And with an acquiescent quaver said: 'Well, Mr. Flood, if you insist, I might.'" - E.A. Robinson
|

09-02-2004, 08:59 AM
|
 |
Senior Contributor
Retired Leader * Expert *
|
|
Join Date: Nov 2003
Location: Buffalo, NY
Posts: 1,145
|
|
any time you work with objects, you need to SET the object to a new instance...
[vb ]
set tmr1 = new Timer
[/vb ]
Edit by jjStinger72: 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...
|
Last edited by jjStinger72; 09-02-2004 at 09:57 AM.
Reason: john beat me to the edit... :)
|

09-02-2004, 08:59 AM
|
 |
Bit Flipper
|
|
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
|
|
Why not use the SetTimer API?
Edit by John: JJ: That won't work.
|
|

09-02-2004, 09:10 AM
|
 |
Centurion
|
|
Join Date: Apr 2004
Location: Missouri
Posts: 145
|
|
|
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
|
__________________
"Before insulting a man, walk a mile in his shoes. That way, he's a mile away and without shoes."
"Convivially returning with himself, Again he raised the jug up to the light;
And with an acquiescent quaver said: 'Well, Mr. Flood, if you insist, I might.'" - E.A. Robinson
|

09-02-2004, 09:53 AM
|
 |
Senior Contributor
Retired Leader * Expert *
|
|
Join Date: Nov 2003
Location: Buffalo, NY
Posts: 1,145
|
|
ah...just tried that with a timer, no good... at least in a module.
quick example using the API
Code:
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
|
|

09-02-2004, 10:21 AM
|
 |
Centurion
|
|
Join Date: Apr 2004
Location: Missouri
Posts: 145
|
|
|
OK, thanks fellas. I was fighting with that same example, and now I see what I'm doing wrong. Thanks a million!
|
__________________
"Before insulting a man, walk a mile in his shoes. That way, he's a mile away and without shoes."
"Convivially returning with himself, Again he raised the jug up to the light;
And with an acquiescent quaver said: 'Well, Mr. Flood, if you insist, I might.'" - E.A. Robinson
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|