Connecting Tech Pros Worldwide Help | Site Map

timer control

  #1  
Old September 15th, 2008, 07:45 AM
John O'Flaherty
Guest
 
Posts: n/a
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
  #2  
Old September 15th, 2008, 09:35 AM
Dean Earley
Guest
 
Posts: n/a

re: timer control


John O'Flaherty wrote:
Quote:
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 (dean.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems
  #3  
Old September 15th, 2008, 10:35 AM
John O'Flaherty
Guest
 
Posts: n/a

re: timer control


On Mon, 15 Sep 2008 09:26:14 +0100, Dean Earley
<dean.earley@icode.co.ukwrote:
Quote:
>John O'Flaherty wrote:
Quote:
>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?)
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Timer Control query Steve answers 3 October 31st, 2008 09:55 AM
Timer Control - No Longer Asynchronous? David answers 3 November 22nd, 2005 02:16 PM
Timer Control - No Longer Asynchronous? David answers 3 November 21st, 2005 02:32 AM
Timer Control - No Longer Asynchronous? David answers 3 July 21st, 2005 06:26 PM
Timer Control William Bub answers 4 July 17th, 2005 10:32 PM