473,413 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

timer control

Hello,
I'm having trouble with the timer control in VB6. I have a form with
a timer control and a command button, and this simple code:

Dim TimeOut As Boolean

Private Sub Form_Load()
Timer1.Interval = 3000
Timer1.Enabled = True
End Sub

Private Sub Command1_Click()
TimeOut = False
While Not TimeOut
Debug.Print TimeOut
Wend
End Sub

Private Sub Timer1_Timer()
TimeOut = True
End Sub

I've enabled the timer, and have set an interval for it, and I would
like the timer to change the state of the global variable TimeOut. On
pressing command1, it goes into an infinite loop, and debugging with a
breakpoint shows that the timer event is never triggered. (It gets
triggered before command1 is pressed, so if you set a breakpoint you
have to press the command button in the first interval to see the
loop.)
Is there something obvious that I'm missing?
--
John
Sep 15 '08 #1
2 2283
John O'Flaherty wrote:
Hello,
I'm having trouble with the timer control in VB6. I have a form with
a timer control and a command button, and this simple code:

Dim TimeOut As Boolean

Private Sub Form_Load()
Timer1.Interval = 3000
Timer1.Enabled = True
End Sub

Private Sub Command1_Click()
TimeOut = False
While Not TimeOut
Debug.Print TimeOut
Wend
End Sub

Private Sub Timer1_Timer()
TimeOut = True
End Sub

I've enabled the timer, and have set an interval for it, and I would
like the timer to change the state of the global variable TimeOut. On
pressing command1, it goes into an infinite loop, and debugging with a
breakpoint shows that the timer event is never triggered. (It gets
triggered before command1 is pressed, so if you set a breakpoint you
have to press the command button in the first interval to see the
loop.)
Is there something obvious that I'm missing?
You need a DoEvents call in the While loop.
There are better ways to handle this though, maybe using the Timer()
function and seeing how long since the loop started.

--
Dean Earley (de*********@icode.co.uk)
i-Catcher Development Team

iCode Systems
Sep 15 '08 #2
On Mon, 15 Sep 2008 09:26:14 +0100, Dean Earley
<de*********@icode.co.ukwrote:
>John O'Flaherty wrote:
>Hello,
I'm having trouble with the timer control in VB6. I have a form with
a timer control and a command button, and this simple code:

Dim TimeOut As Boolean

Private Sub Form_Load()
Timer1.Interval = 3000
Timer1.Enabled = True
End Sub

Private Sub Command1_Click()
TimeOut = False
While Not TimeOut
Debug.Print TimeOut
Wend
End Sub

Private Sub Timer1_Timer()
TimeOut = True
End Sub

I've enabled the timer, and have set an interval for it, and I would
like the timer to change the state of the global variable TimeOut. On
pressing command1, it goes into an infinite loop, and debugging with a
breakpoint shows that the timer event is never triggered. (It gets
triggered before command1 is pressed, so if you set a breakpoint you
have to press the command button in the first interval to see the
loop.)
Is there something obvious that I'm missing?

You need a DoEvents call in the While loop.
There are better ways to handle this though, maybe using the Timer()
function and seeing how long since the loop started.
The DoEvents fixed it for me. Thanks.
--
John
(what are we doing up at this time of night?)
Sep 15 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: William Bub | last post by:
Is there an accurate way to create a "stopwatch" good to 1/10 of a second? I'm not sure if I should use the timer control, or some way to access the computer timer. I found the following site...
3
by: David | last post by:
Hi There! I'm using Timer control to record how long my application perform certain tasks. However, apparently Timer control is not doing its' job (i.e. Not firing Tick event) while my...
11
by: Steve Jorgensen | last post by:
I've recently been playing with some UI ideas that require the user of a timer to drive animation. The problem I'm having is that Access routinely stops firing timer events for long periods of...
5
by: Dhilip Kumar | last post by:
Hi all, I have developed a windows service using the windows service project template in VS.NET. I have used three controls in the service, a timer, performance counter and a message queue...
7
by: Noozer | last post by:
I have a timer on a form. It isn't firing at all. I know that the timer is enabled, and that the interval is low (4000, which should be 4 seconds). To ensure the timer wasn't being inadvertantly...
2
by: vinay | last post by:
Hi I must be missing some obvious point, but can someone let me know how do I add a windows.forms.timer control to a form at run time Private TM as new windows.forms.time Dim sForm as for ...
7
by: RobKinney1 | last post by:
Hello, Wow...I have one for you all and hopefully I am not understanding this timer object correctly. I have a timer setup that pulses a connection through a socket every 60 seconds. But it...
4
by: grayaii | last post by:
Hi, I have a simple form that handles all its paint functionality like so: this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); And the entry point to this...
4
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i have a main thread an another worker thread. The main Thread creates another thread and waits for the threads signal to continue the main thread. Everything works inside a ModalDialog and...
3
by: Steve | last post by:
Hi All I am using VB.net 2008 and use timer controls within my applications Question Does the code in a Timer control.tick event run on a different thread to the main Application thread (UI...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.