 |
|
 |
hi 
you should use a PerformenceCounter (Tickcount) instead of the DateTime object because using the DateTime functionality in "Real-Time processes" will give back "wrong" milliseconds (not really real-time milliseconds..)! The DateTime internal updates only if ~10ms passed, under 10ms nothing will be handled..
So if you need a stopwatch that works correct under 10milliseconds you can't work like here..
greetings..
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I wanted to start a timer and when it reaches to certain fixed time, need to do certain action. how to make this out in ASP.net? Some one said to use Stopwatch but i am not able to start that in one method and find the current time in another method. it seems it gets stopped as soon as that method gets over.
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
your VB script bellow is working well, but how to get interval time between after click start button and click stop button, hope you can help me the code, thanks
Dim startTime As DateTime
Private Sub Timer1_Tick(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Timer1.Tick Dim span As TimeSpan = DateTime.Now.Subtract(startTime) Label1.Text = span.Minutes.ToString & ":" & _ span.Seconds.ToString & "." & span.Milliseconds End Sub
Private Sub Label1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Label1.Click If (Timer1.Enabled) Then Me.Text = "Click to Re-start" Timer1.Stop() Else startTime = DateTime.Now() Me.Text = "Click to Stop" Timer1.Start() End If End Sub
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
your VB script bellow working well :
Dim startTime As DateTime
Private Sub Timer1_Tick(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Timer1.Tick Dim span As TimeSpan = DateTime.Now.Subtract(startTime) Label1.Text = span.Minutes.ToString & ":" & _ span.Seconds.ToString & "." & span.Milliseconds End Sub
Private Sub Label1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Label1.Click If (Timer1.Enabled) Then Me.Text = "Click to Re-start" Timer1.Stop() Else startTime = DateTime.Now() Me.Text = "Click to Stop" Timer1.Start() End If End Sub
But, how to catch the interval after click start button until click stop button? hope you can help me the code
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
as you said in your fantastic article the application must not be big and includes much code always the small application perhaps be useful
My name is Nabil Isamil El-Esawy I am a developer I start programming since just one year I learned VB6,VB.NET For communication nma202000@msn.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
i have implemented in my application (hobby, not real developing!), but changed a few things here an there and made it in Panel (VB 2005) and have a button to click, start, restart and, also a button to reset (it simply changes the button text to Click to Start and the Label to 00:00:00!) if you want the code here it is: Make Label19 and Button3 with those names. change button 3.s text to START TIMER. change label19 to 00:00:00. make Timer1. double click Button3 and put this in Button3 click in the code.
If (Timer1.Enabled) Then Button3.Text = "RESTART" Timer1.Stop() Else startTime = DateTime.Now() Button3.Text = "STOP TIMER" Timer1.Start() End If
add this to your code (The form Class):
Private Sub Timer1_Tick(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Timer1.Tick Dim span As TimeSpan = DateTime.Now.Subtract(startTime) Label19.Text = span.Minutes.ToString & ":" & _ span.Seconds.ToString & "." & span.Milliseconds End Sub
 goodbye. pls send any suggestions on this contact page: http://tinyurl.com/386jsp
vb.net developer!
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
If you replace DateTime.Now with Environment.TickCount, you avoid instantiating DateTime objects and you end up subtracting numbers (longs) instead of DateTimes. DateTime.Now has more overhead than you might think because it deals with things like culture information and time zones, and the Subtract method has to do a bit of work to get the result. Also, you never know, but Windows XP might decide to synchronize your clock with time.windows.com while the stopwatch is on...
-Nadeem
|
| Sign In·View Thread·PermaLink | 3.86/5 (4 votes) |
|
|
|
 |
|
 |
Thanks! This article was very useful for a PDA application I'm writing. The only alterations I made were:
- the timer's start and stop methods were not recognised so they were replaced with Timer1.Enabled = True or Timer1.Enabled = False
- The label's click event wouldn't fire so I switched the label for a button
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Hi
First of all thanks for this. I followed the steps and managed to get the Timer working. I then played about with the code and managed to replace milliseconds with hours.
When you first launch the application the timer starts at the current time of day. Can someone please help me to configure the timer to start from zero on launch.
Regards
ensuvari
|
| Sign In·View Thread·PermaLink | 1.75/5 (4 votes) |
|
|
|
 |
|
 |
I took my time, and I was able to create, and make the timer work first time around.
I feel pretty good since I have almost zero experience with programming. This is my forth week in a vb net class, just working on console application, which I find difficult at this point, but I had very little trouble fallowing your directions.
Thanks again
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Alastair, this has helped me out a lot too... but I have tried unsuccessfully to make the stopwatch continue where it left off after 'stop' then 'continue' buttons are clicked. A new timer is started after the 'stop' button is clicked, and the 'continue' button only reveals the new timer counting away. Any help? thanks in advance, Alex.
|
| Sign In·View Thread·PermaLink | 2.33/5 (3 votes) |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Had to change source to this to make this work.
Private Sub Timer1_Tick(ByVal sender As System.Object, _ ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
|
| Sign In·View Thread·PermaLink | 5.00/5 (2 votes) |
|
|
|
 |
|
 |
Hi Dallas!
I'm an old C/C++ programmer also active on CP and want to know more about VB .net - just don't know where to begin. Think I'll download your app. and play with it. Thank's for your contribution - btw. what's the big deal in going from VB 6.0 til VB .net anyway?
Regards, Michael Mogensen, mm it-consult dk.
><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
There is a very big deal in going from VB6 to VB.NET.
I guess the biggest difference is Object oriented language. VS.NET 2003 is a move in the right direction for sure, but I have read that 2005 will complete what 2003 version started.
Needless to say that VS.NET 2003 left much to be desired. 
I know you're comment string is old, but I thought I would appease your tease
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |