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