Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Create Timer From Code


Reply
 
Thread Tools Display Modes
  #1  
Old 09-02-2004, 08:54 AM
Ineluki's Avatar
Ineluki Ineluki is offline
Centurion
 
Join Date: Apr 2004
Location: Missouri
Posts: 145
Question 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
Reply With Quote
  #2  
Old 09-02-2004, 08:59 AM
jjStinger72's Avatar
jjStinger72 jjStinger72 is offline
Senior Contributor

Retired Leader
* Expert *
 
Join Date: Nov 2003
Location: Buffalo, NY
Posts: 1,145
Default


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...
__________________
Jay

[vb][/vb] Tags | Standards & Practices Tutorial | File I/O Tutorial | List of all these Tags

Last edited by jjStinger72; 09-02-2004 at 09:57 AM. Reason: john beat me to the edit... :)
Reply With Quote
  #3  
Old 09-02-2004, 08:59 AM
John's Avatar
John John is offline
Bit Flipper
 
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
Default

Why not use the SetTimer API?

Edit by John: JJ: That won't work.
__________________
Subclassing|Magnetic Forms|Operator Overloading (VB2K5)|QuickSnip.NET

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy
Reply With Quote
  #4  
Old 09-02-2004, 09:10 AM
Ineluki's Avatar
Ineluki Ineluki is offline
Centurion
 
Join Date: Apr 2004
Location: Missouri
Posts: 145
Default

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
Reply With Quote
  #5  
Old 09-02-2004, 09:53 AM
jjStinger72's Avatar
jjStinger72 jjStinger72 is offline
Senior Contributor

Retired Leader
* Expert *
 
Join Date: Nov 2003
Location: Buffalo, NY
Posts: 1,145
Default

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
__________________
Jay

[vb][/vb] Tags | Standards & Practices Tutorial | File I/O Tutorial | List of all these Tags
Reply With Quote
  #6  
Old 09-02-2004, 10:21 AM
Ineluki's Avatar
Ineluki Ineluki is offline
Centurion
 
Join Date: Apr 2004
Location: Missouri
Posts: 145
Default

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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->