timer control 
September 15th, 2008, 07:45 AM
| | | |
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 | 
September 15th, 2008, 09:35 AM
| | | | 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 | 
September 15th, 2008, 10:35 AM
| | | | 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?) |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|