quote:
Originally posted by j.g.allen
The program reads down each of the lines of the text file until it finds the .-------. bit. It goes down to the next line
quote:
Originally posted by j.g.allen
This reads the session start date.
and plugs it into an array.
But why do you need this? The date is actually of no use when calculating the total time of chat in that log...
quote:
Originally posted by j.g.allen
There is no way I know of to go back easily in a text file.
consult your helpfiles (or the microsoft msdn library). To move the filepointer (in any type of file) use the statement "seek" (also works as a function).
quote:
Seek Statement: Sets the position for the next read/write operation within a file opened using the Open statement.
Syntax: Seek [#]filenumber, position
The Seek statement syntax has these parts:
filenumber Required. Any valid file number.
position Required. Number in the range 1 – 2,147,483,647, inclusive, that indicates where the next read/write operation should occur.
Remarks:
Record numbers specified in Get and Put statements override file positioning performed by Seek.
Performing a file-write operation after a Seek operation beyond the end of a file extends the file. If you attempt a Seek operation to a negative or zero position, an error occurs. (in VB the file starts at position 1 not 0)
Example:
Dim sTextLine as String
Open "TESTFILE" For Input As #1
MsgBox "Size of file:" & LOF(1)
Do While Not EOF(1)
Line Input #1, sTextLine
Debug.Print sTextLine
Loop
'Go back to the beginning
Seek #1, 1
Do While Not EOF(1)
Line Input #1, sTextLine
Debug.Print sTextLine
Loop
Close #1
quote:
Originally posted by j.g.allen
This reads the 8 chars of the time after the [.
Not realy, it gets a substring from t starting at position 2 and (now the important part) reads the next 8 characters
if they exist. This means if you have a line like in my testlog (the last line of the file) it will not return a string of 8 characters in length.
quote:
Originally posted by j.g.allen
1) The program reads down each of the lines of the text file until it finds the .-------. bit.
2) It goes down to the next line: SessionStartDates(I) = Mid(TxtLine.ReadLine, 17, 20)
3) It keeps reading down, and skips the next .----. because thats the bottom of the box.
4) It repeats steps 1-3 until the end of the file, and then closes it.
5) The same file is then reopened to start at the start of the file again.
6) This time we skip the first .---. and move the next one: SessionStartTimeStr = Mid(t, 2, 8)
7) Again, this (step 6) is a repeated process to get all the session start times.
You're making it way to complicated though
1)
that's a very good start. This makes sure that garbage in front of the file is skipped...
2) Date should be ignored, it is of no use for this program...
3) Here you already complicate things
This isn't needed... I'll explain later with an example...
4) Why not doing what you're doing in step 6 (reading the times) in here? There is no need to process the whole file, close it, reopen it and start again with actually the same process.
5) Thus, like said in step 4, read the times directly from the first time.
6) Again complicating things...
This pseudo-code is all you need to read those logs in one go and calculating the total chattime. It will skip over garbage automatically (because the only two acceptable lines are the ones with ".-----." and the ones with "[??:??:??]" (because that is all you need).
code:
GarbageSkipped = False
StartCounting = False
TotalTime = 00:00:00
StartTime = 00:00:00
Open "TESTLOG" For Input As #1
While Not EOF(1)
Line Input #1, sTextLine
If sTextLine = ".-----." Then
GarbageSkipped = True
StartCounting = True
ElseIf (sTextLine = "[??:??:??]") And (GarbageSkipped = True) Then
FoundTime = GetTheTimeFrom(sTextLine)
If StartCounting = True Then
StartCounting = False
Else
TotalTime = TotalTime + FoundTime - StartTime
If FoundTime < StartTime Then TotalTime = TotalTime + 24
End If
End If
StartTime = FoundTime
Wend
Close #1
Print "Total time chatted: " & TotalTime
I also attached a very commented VB source code which works with all the chatlogs (24h timeformat of course and in the form of "[??:??:??]", and the logs need to be saved as ASCII (thus unicode logs will not be read))
The source opens and correctly calculates my previous posted testlog file.
(note that the code can also be optimized a lot and made much more efficient though)
rest is up to you