id10t error wrote:
I am makeing a program that will track productivity by every time a
button is pushed i write a record to a text file. The text file
contain the time in HHMMSS format.
Why? That's not a date format that Visual Basic can make sense of, so
why not save yourself a headache or two and use one that it can use?
DateTime.Now.ToString( "yyyy/MM/dd hh:mm:ss" )
will parse back into a DateTime variable very nicely, thank you.
The next time they press a button i want to read the last time and
find the span of time between the two buttons being pushed.
Far better to store this value in the program and calculate the elapsed
time based on that, rather than re-reading the file (which could get
very big and hence very slow to read).
Class Timings
Public Shared gLastActionTime as DateTime = DateTime.MinValue
Public Shared Sub TimedAction(sActionName as String)
Dim dtNow as DateTime = DateTime.Now
Dim lElapsed as Integer = 0
If gLastActionTime <DateTime.MinValue Then
lElapsed = dtNow.Subtract( gLastActionTime ).TotalMilliseconds
End If
gLastActionTime = dtNow
WriteToFile( "{0:yyyyMMdd hh:mm:ss}|{1}|{2}" _
, dtNow, lElapsed, sActionName )
End Sub
HTH,
Phill W.