|
-
Jul 31st, 2012, 03:20 PM
#1
Thread Starter
Member
Timers...
Last edited by jbailey01; Jul 31st, 2012 at 03:28 PM.
-
Jul 31st, 2012, 03:29 PM
#2
Re: Timers...
You don't need a timer for this. You can use a StopWatch, or a simple datetime variable. Start the stopwatch or set the variable to the current datetime in form load. Later, when you need to know how much time has elapsed, you read the Elapsed property of the stopwatch or subtract the saved datetime from the current datetime.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jul 31st, 2012, 03:31 PM
#3
Re: Timers...
Try
Code:
Private i As Integer
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
With Timer1
.Interval = 1000 '1 Second
.Start()
End With
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
i += 1
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
MessageBox.Show("It's been " & i.ToString & " seconds since the form's loaded", Me.Text, MessageBoxButtons.OK)
End Sub
Edit - Why just edit your op to "nevermind"? That's annoying. But stanav's correct, you should use a stopwatch. For those of you wondering, the origional post was "How do I keep track of the time lapsed since my formload?".
Edit 2 - This is the samething using a stopwatch:
Code:
Dim sw As New Stopwatch
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
sw.Start()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim i As Integer = CInt(sw.ElapsedMilliseconds)
i = CInt(i * 0.001)
MessageBox.Show("It's been " & i.ToString & " seconds since the form's loaded", Me.Text, MessageBoxButtons.OK)
End Sub
Last edited by dday9; Jul 31st, 2012 at 03:48 PM.
-
Jul 31st, 2012, 03:39 PM
#4
Thread Starter
Member
Re: Timers...
Thank you guys. I thought my code was wrong, but it was another peice of the pie. Very much appreciated!!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|