M
MikeS
Can someone tell me why my program hangs when I call a timer function from
within a Do Loop. Here is the code:
Public Class MainForm
Public intCounter As Double = 0
Public intMin As Double
Public intSec As Double
Private Sub btnStart_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnStart.Click
If btnStart.Text = "Start" Then
btnStart.Text = "Stop"
Else
btnStart.Text = "Start"
End If
lblTimeMin.Text = "0:"
lblTimeSec.Text = "00"
'Do While intCounter < 600
Call MyTimer()
intCounter = intCounter + 1
intMin = Int(intCounter / 60)
intSec = intCounter Mod 60
lblTimeMin.Text = Convert.ToString(intMin & ":")
lblTimeSec.Text = Convert.ToString(Format(intSec, "00"))
'Loop
End Sub
Private Sub MyTimer()
Dim start, finish As Double
start = Microsoft.VisualBasic.DateAndTime.Timer
finish = start + 1
Do While Microsoft.VisualBasic.DateAndTime.Timer < finish
Loop
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
Thanks,
Mike
within a Do Loop. Here is the code:
Public Class MainForm
Public intCounter As Double = 0
Public intMin As Double
Public intSec As Double
Private Sub btnStart_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnStart.Click
If btnStart.Text = "Start" Then
btnStart.Text = "Stop"
Else
btnStart.Text = "Start"
End If
lblTimeMin.Text = "0:"
lblTimeSec.Text = "00"
'Do While intCounter < 600
Call MyTimer()
intCounter = intCounter + 1
intMin = Int(intCounter / 60)
intSec = intCounter Mod 60
lblTimeMin.Text = Convert.ToString(intMin & ":")
lblTimeSec.Text = Convert.ToString(Format(intSec, "00"))
'Loop
End Sub
Private Sub MyTimer()
Dim start, finish As Double
start = Microsoft.VisualBasic.DateAndTime.Timer
finish = start + 1
Do While Microsoft.VisualBasic.DateAndTime.Timer < finish
Loop
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
Thanks,
Mike