| View previous topic :: View next topic |
| Author |
Message |
I'm C.H. Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Dec 2006 Posts: 1000 Location: Sweden
|
Posted: Sat Dec 20, 2008 10:39 am Post subject: [Vb.net] Question about a Timer. |
|
|
Well, I am making a timer that counts Hours, Seconds and Minutes. I've done everything so far but I need to know this one thing:
The Stop timer button stops the counting but when you start it again, the timers are back to default value. How can I make so that the timers only get paused?
Thx!
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sat Dec 20, 2008 2:12 pm Post subject: |
|
|
I don't get exactly what the problem is here, how are you losing count? You can also try stopping a timer by simply setting the Enabled property to false.
You may find this easier to do with the DateTime and TimeSpan structures
Just find the difference by subtracting.
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Sun Dec 21, 2008 3:12 am Post subject: |
|
|
use global variables, so they keep their values, show you code if you want me to show ya what i mean
_________________
|
|
| Back to top |
|
 |
yoyonerd Grandmaster Cheater
Reputation: 0
Joined: 26 Apr 2008 Posts: 699 Location: -->formerly yoyonerd<--
|
Posted: Sun Dec 21, 2008 3:18 am Post subject: |
|
|
are you using the timer control? or there's one in c# so im sure in vb.net that the stopwatch class exists as well
like snootae, post ur code, so we know whats wrong
_________________
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Sun Dec 21, 2008 4:26 am Post subject: |
|
|
hes using a timer control, but i dont recall that there was a resume / suspend function, but if its just counting, no point in using local vairables
_________________
|
|
| Back to top |
|
 |
I'm C.H. Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Dec 2006 Posts: 1000 Location: Sweden
|
Posted: Sun Dec 21, 2008 9:30 am Post subject: |
|
|
| Code: | Public Class Form1
Dim Secs As Integer
Dim Mins As Integer
Private Sub Seconds_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Seconds.Tick
Secs = Secs + 1
Label3.Text = "Seconds: " & Secs
If Int(Label1.Text / 60) = Label1.Text / 60 Then Label2.Text = Label2.Text + 1
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Seconds.Start()
End Sub
Private Sub Minutes_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Minutes.Tick
Mins = Mins + 1
Label2.Text = "Minutes: " & Mins
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Seconds.Enabled = False
Minutes.Enabled = False
Hours.Enabled = False
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Seconds.Enabled = False
Minutes.Enabled = False
Hours.Enabled = False
Label1.Text = "Hours: 0"
Label2.Text = "Minutes: 0"
Label3.Text = "Seconds: 0"
Seconds.Start()
Minutes.Start()
Hours.Start()
End Sub
End Class
|
_________________
|
|
| Back to top |
|
 |
Kerelmans Advanced Cheater
Reputation: 0
Joined: 29 Oct 2007 Posts: 57
|
Posted: Mon Dec 22, 2008 2:57 pm Post subject: |
|
|
How about storing the time when the user starts, then make a timer tick every sec:
yourtime = $time - oldtime
(to lazy to actually make it xD)
should work...
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Mon Dec 22, 2008 8:22 pm Post subject: |
|
|
| Code: | Public Class Form1
Dim secs, mins, hours As Integer
Private Sub Time_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Seconds.Tick
secs = secs + 1
Label3.Text = "Seconds: " & secs
If secs = 60 Then
mins += 1
secs = 0
Label3.Text = "Minutes: " & mins
If mins = 60 Then
hours += 1
mins = 0
Label1.Text = "Hous: " & hours
End If
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Time.enabled = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Time.enabled = False
End Sub |
eliminates the need for multiple timers, and keeps time
i dont know exatly what the point fo you button3 is, if it just resets it then
| Code: | secs = 0
mins = 0
hours = 0 |
_________________
|
|
| Back to top |
|
 |
yoyonerd Grandmaster Cheater
Reputation: 0
Joined: 26 Apr 2008 Posts: 699 Location: -->formerly yoyonerd<--
|
Posted: Mon Dec 22, 2008 10:21 pm Post subject: |
|
|
is it a countdown timer, or a count up timer
_________________
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Mon Dec 22, 2008 10:27 pm Post subject: |
|
|
id say up
_________________
|
|
| Back to top |
|
 |
|