how can i create a stop watch using vb.net 2005 i am performing a data extraction job using windows forms and want to display time elapsed on the form. how can i do it
I tried your code and it worked fine. Of course I don't know how you declare stopWatch, tmrMain and what CreateReport does; so I just created standard components and commented out CreateReport.
It is strange that you did not hit a break point in tmrMain_Tick. Did you try putting a breakpoint on If stopWatch.IsRunning Then
Without more code I'm afraid I cannot investigate further.
Yes, Enabled property is set to True and Interval property is set to 50. I placed a breakpoint on the tick event and surprisingly it doesn't break into the event
Using Stopwatch class i am displaying the elapsed time in a label on the form. The problem is that time elapsed time is not getting updated in the label. It shows the elapsed time as soon as i click the button to start processing data and doesn't update elapsed time there after. below is the code
Private Sub btnCreateReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateReport.Click
stopWatch.Start() Call CreateReport()
End Sub
Private Sub tmrMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMain.Tick
Using Stopwatch class i am displaying the elapsed time in a label on the form. The problem is that time elapsed time is not getting updated in the label. It shows the elapsed time as soon as i click the button to start processing data and doesn't update elapsed time there after. below is the code
Private Sub btnCreateReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateReport.Click stopWatch.Start() Call CreateReport() End Sub
Private Sub tmrMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMain.Tick If stopWatch.IsRunning Then Dim ts As TimeSpan = stopWatch.Elapsed lblTimer.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", _ ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10) End If End Sub
Using Stopwatch class i am displaying the elapsed time in a label on the form. The problem is that time elapsed time is not getting updated in the label. It shows the elapsed time as soon as i click the button to start processing data and doesn't update elapsed time there after. below is the code
Private
Sub btnCreateReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateReport.Click
stopWatch.Start()
Call CreateReport()
End
Sub
Private
Sub tmrMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMain.Tick If stopWatch.IsRunning Then
Dim ts As TimeSpan = stopWatch.Elapsed lblTimer.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", _ ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)
stop watch using vb.net 2005
Fab IT
Set a breakpoint on the tick event to see if you reach the tick event at all.
JanBaan
I tried your code and it worked fine. Of course I don't know how you declare stopWatch, tmrMain and what CreateReport does; so I just created standard components and commented out CreateReport.
It is strange that you did not hit a break point in tmrMain_Tick. Did you try putting a breakpoint on If stopWatch.IsRunning Then
Without more code I'm afraid I cannot investigate further.
Regards,
jswilson
Yes, Enabled property is set to True and Interval property is set to 50. I placed a breakpoint on the tick event and surprisingly it doesn't break into the event
wht cud be the prob!
BaNgInG
i suggest to use a Timer control from the toolbox and display it on a label to
the user
sp_412000
yennisse
Using Stopwatch class i am displaying the elapsed time in a label on the form. The problem is that time elapsed time is not getting updated in the label. It shows the elapsed time as soon as i click the button to start processing data and doesn't update elapsed time there after. below is the code
Private Sub btnCreateReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateReport.Click
stopWatch.Start()
Call CreateReport()
End Sub
Private Sub tmrMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMain.Tick
If stopWatch.IsRunning Then
Dim ts As TimeSpan = stopWatch.Elapsed
lblTimer.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", _
ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)
End If
End Sub
Thanks
Ram Marappan
Would you try adding this into btnCreateReport_Click It looks like you forgot to start the timer.
tmrMain.Start()
Hope this helps,
M. Buragohain
Marinus
Hayder Marzouk
Application.DoEvents()
Cathal
CodeNet
FreakFrossard
i am starting the timer as it's Enabled property is set to True on form load.
Jamskin Chen
Using Stopwatch class i am displaying the elapsed time in a label on the form. The problem is that time elapsed time is not getting updated in the label. It shows the elapsed time as soon as i click the button to start processing data and doesn't update elapsed time there after. below is the code
Private Sub btnCreateReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateReport.Click
stopWatch.Start()
Call CreateReport()
End Sub
Private Sub tmrMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMain.Tick
If stopWatch.IsRunning Then
Dim ts As TimeSpan = stopWatch.Elapsed
lblTimer.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", _
ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)
End If
End Sub
Aaron Steers
Thanks
reZer
Using Stopwatch class i am displaying the elapsed time in a label on the form. The problem is that time elapsed time is not getting updated in the label. It shows the elapsed time as soon as i click the button to start processing data and doesn't update elapsed time there after. below is the code
Private
Sub btnCreateReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateReport.ClickstopWatch.Start()
Call CreateReport()End
SubPrivate
Sub tmrMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMain.Tick If stopWatch.IsRunning ThenDim ts As TimeSpan = stopWatch.Elapsed lblTimer.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", _
ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)
End If End Sub
Thanks