Nevermind
Printable View
Nevermind
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.
Try
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?".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 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
Thank you guys. I thought my code was wrong, but it was another peice of the pie. Very much appreciated!!