measuring elapsed time

cherenee

Member
Joined
Apr 15, 2007
Messages
6
Programming Experience
Beginner
I am working on a game like suduko. After the game is won, I would like to have my message box pop up showing the amount of time that has lasped.
So far with the code I have, the message window pops up first and counts every second non stop in individual windows. What am I doing wrong!?:confused:

Code:
Public Class...
Dim TimeTaken as Integer
.
.
.
.
Private Sub...
TimeTaken = TimeTaken + 1
MessageBox.Show ("Time taken is" & TimeTaken & "seconds")

Thanks!
 
remove the message box from your timer event.
display msgbox when you finish game + set timer.enabled = false
 
I don't really get the question, I think. But I do the following in some apps:
VB.NET:
        Dim startTime, endTime As Date
        startTime = Now  'when you want the 'clock' to start
        'do stuff here
        endTime = Now
        MsgBox("Run time was: " & (endTime - startTime).ToString)
 
I am working on a game like suduko. After the game is won, I would like to have my message box pop up showing the amount of time that has lasped.
So far with the code I have, the message window pops up first and counts every second non stop in individual windows. What am I doing wrong!?:confused:

Code:
Public Class...
Dim TimeTaken as Integer
.
.
.
.
Private Sub...
TimeTaken = TimeTaken + 1
MessageBox.Show ("Time taken is" & TimeTaken & "seconds")

Thanks!

This may be too easy, but just put a timer event on your project...

Private totaltime as Integer = 0

Private Sub StartGame()
Timer1.Start
End Sub

Private Sub EndGame()
Timer1.Stop
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
totaltime = totaltime + 1
End Sub

Once you have how many seconds, you can convert the seconds into minutes, hours, etc... Make sure your timer event is set to 1000 ms ( think it's the default value )
 
Don't use a Timer so measure time, it is a component used to make something happens at intervals, also the intervals may not be accurate if OS is busy. Instead do clweeks simple suggestion with a start Date and end Date or use the StopWatch class.
 
Back
Top