Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

2 stopwatch timers one copies the others time when run together

Ive got a form with 4 stopwatch timers that when hours min or seconds is selected and a number put in 1 textbox and an url in another the stopwatch timer counts down then launches the website. The problem I have is stopwatch timer 3 & 4. Both run fine without the other but if 1 ad 60 seconds in stopwatch 3 then 30 in stopwatch 4 run together SW3 changes to SW4 and they both show the same time. Both on different timers.

I cant find whats causing this to happen.Here is the code for both clocks. Like I said when run together SW3 then copys SW4. Can anyone see why this is happening. Ive been all over it and it looks fine. Maybe a fresh paire of eyes will help.
I hope that made sense :/

Code
' Start Button for SW3******
Button17.Visible = False
      If RadioButton1.Checked = True Then
      Me.alarmTime = Date.Now.AddHours(input3.Text)
      Me.Timer3.Start()
      ElseIf RadioButton2.Checked = True Then
      Me.alarmTime = Date.Now.AddMinutes(input3.Text)
      Me.Timer3.Start()
      ElseIf RadioButton3.Checked = True Then
      Me.alarmTime = Date.Now.AddSeconds(input3.Text)
      Me.Timer3.Start()
      End If

'  Timer for SW3******
Private Sub Timer8_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick
      If alarmTime < Date.Now Then
      Me.Timer3.Stop()
      Button17.Visible = True
      System.Diagnostics.Process.Start(url3.Text)
      Call Audio()
      Me.Visible = True
      Else
      Dim remainingTime As TimeSpan = Me.alarmTime.Subtract(Date.Now)
      Me.clock3.Text = String.Format("{0}:{1:d2}:{2:d2}", _
      remainingTime.Hours, _
      remainingTime.Minutes, _
      remainingTime.Seconds)
      End If
    End Sub
******
' Start button for SW4******
Button15.Visible = False
      If RadioButton12.Checked = True Then
      Me.alarmTime = Date.Now.AddHours(input4.Text)
      Me.Timer4.Start()
      ElseIf RadioButton11.Checked = True Then
      Me.alarmTime = Date.Now.AddMinutes(input4.Text)
      Me.Timer4.Start()
      ElseIf RadioButton10.Checked = True Then
      Me.alarmTime = Date.Now.AddSeconds(input4.Text)
      Me.Timer4.Start()
      End If

' Timer for SW4******
Private Sub Timer7_Tick(sender As Object, e As EventArgs) Handles Timer4.Tick
      If alarmTime < Date.Now Then
      Me.Timer4.Stop()
      Button15.Visible = True
      System.Diagnostics.Process.Start(url4.Text)
      Call Audio()
      Me.Visible = True
      Else
      Dim remainingTime As TimeSpan = Me.alarmTime.Subtract(Date.Now)
      Me.clock4.Text = String.Format("{0}:{1:d2}:{2:d2}", _
      remainingTime.Hours, _
      remainingTime.Minutes, _
      remainingTime.Seconds)
      End If
    End Sub
Why not just use 1 timer only for seconds:
You create a variable and store the start time in there (when someone starts the timer!)
You also create a variable in which the duration of the time is stored (How long it is supposed to time)

Then in your timer you just check the difference in time and build on further from that.
Thanks for the quick reply backshifted

Once the user has selected what they want the timer to count down in for example hours, minutes or seconds they can then enter a number input.Text so if they enter 30 and the seconds RadioButton checked it will be a 30sec timer select Minutes its then a 30 minute timer. So the start time can be anything the user wants really.

There is also 4 of these that all run at the same time.

[Image: d19lNBJ.png]
You are using the same variable for AlarmTime, that is probably causing your issue :P
I agree with backshifted, using just 1 timer will be the best solution, there is no need for 4 timers.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Bora or HyunaJan 27, 2020 12:26 PM 6 178 Jan 27, 2020 12:26 PM
Last Post: Lindros
[Java] by deadsh0tJun 12, 2019 06:27 AM 0 115 Jun 12, 2019 06:27 AM
Last Post: deadsh0t
[.NET] by selfieman231Dec 11, 2016 04:22 PM 5 155 Dec 11, 2016 04:22 PM
Last Post: selfieman231