Howdy!
I have created a large application which preforms many functions. One of these functions is to read log files created by another program.
Here is a sample log file: (copy into notepad for the example)
In case you didn't guess, this is a Microsoft Flight Simulator 2000 Logbook file.Code:Chris's Logbook
FS2000
DATE AIRCRAFT MODEL TO/FROM/REMARKS DAY NIGHT INST. TOTAL
8/2/2000 CESSNA C152 Full CC-KAA turns,climbs,descents 1.0 0.0 0.0 1.0
8/7/2000 CESSNA C152 Full CC-KAA cfg changes,stalls,T&G 1.1 0.0 0.0 1.1
8/8/2000 CESSNA C152 Full CC-KAA steep turns,stalls,T&G 1.5 0.0 0.0 1.5
8/11/2000 CESSNA C152 Full CC-KAA Instrument work 1.2 0.0 0.5 1.2
8/13/2000 CESSNA C152 Full CC-KAA Instrument work 1.5 0.0 0.5 1.5
8/14/2000 CESSNA C152 Full CC-KAA T&G at BIL 0.8 0.0 0.0 0.8
8/17/2000 CESSNA C152 Full CC-KAA Instrument Work 1.4 0.0 0.5 1.4
8/21/2000 CESSNA C152 Full CC-KAA T&G at BIL 0.9 0.0 0.0 0.9
8/28/2000 CESSNA C152 Full CC-KAA T&G at BIL 0.8 0.0 0.0 0.8
9/10/2000 CESSNA C152 Full CC-KAA T&G at BIL 0.8 0.0 0.0 0.8
9/15/2000 CESSNA C152 Full CC-KAA FIRST SOLO 1.2 0.0 0.0 1.2
9/17/2000 CESSNA C152 Full CC-KAA Supervised solo at BIL 1.2 0.0 0.0 1.2
9/27/2000 CESSNA C152 Full CC-KAA Solo at BIL 0.6 0.0 0.0 0.6
10/17/2000 CESSNA C152 Full CC-KAA emergency procedures 0.6 0.0 0.0 0.6
10/21/2000 CESSNA C152 Full CC-KAA Solo north practice area 0.8 0.0 0.0 0.8
10/22/2000 CESSNA C152 Full CC-KAA Solo north practice area 0.7 0.0 0.0 0.7
10/28/2000 CESSNA C152 Full CC-KAA Solo north practice area 0.8 0.0 0.0 0.8
12/2/2000 CESSNA C152 Full CC-KAA Dual cross country 2.1 0.0 0.0 2.1
12/22/2000 CESSNA C152 Full CC-KAA Instrument work 1.1 0.0 0.5 1.1
1/20/2001 CESSNA C152 Full CC-KAA T&G at BIL 0.5 0.0 0.0 0.5
2/10/2001 CESSNA C152 Full CC-KAA Solo cross country 2.3 0.0 0.0 2.3
2/18/2001 CESSNA C152 Full CC-KAA soft field landings 1.2 0.0 0.0 1.2
3/25/2001 CESSNA C152 Full CC-KAA T&G at BIL 0.8 0.0 0.0 0.8
3/31/2001 CESSNA C152 Full CC-KAA Solo Cross Country 2.9 0.0 0.0 2.9
4/7/2001 CESSNA C152 Full CC-KAA T&G at Laurel 1.1 0.0 0.0 1.1
4/14/2001 CESSNA C152 Full CC-KAA T&G at BIL crosswind 0.7 0.0 0.0 0.7
5/12/2001 CESSNA C152 Full CC-KAA Solo North Practice Area 1.2 0.0 0.0 1.2
6/2/2001 CESSNA C152 Full CC-KAA Solo north practice area 1.1 0.0 0.0 1.1
TOTALS 31.9 0.0 2.0 31.9
I'm having trouble reading the file. Here is the code I have:
OK, the idea is to take sHeader:Code:On Error GoTo ErrHandler
Open App.Path & "\Chris's Logbook.txt" For Input As #1
Line Input #1, FileTitle
Line Input #1, BlankLine
Line Input #1, FileFormat
Line Input #1, sHeader
Line Input #1, BlankLine
Do 'Start a loop which will make an error when the file is done
Line Input #1, sLine
sData = sData & "~<!~>" & sLine 'Put the data into a string with a wierd code between each line
Text1.Text = Text1.Text & vbCrLf vbCrLf & sLine 'Put it into a textbox
Loop
Close #1
Done:
'Here we would split up the array and put it in a listview - I have 'that code, but it is not important for this example.
If FileFormat <> "FS2000" Then
MsgBox "This file is from a version of Flight Simulator other than 2000 or is not a valid logbook file. While FSLogbook may still read the file, some errors may occur.", vbInformation
End If
Me.Caption = "Log Book - " & FileTitle
Exit Sub
ErrHandler:
Select Case Err.Number
Case 62
Resume Done
Case Else
MsgBox "Runtime error " & Err.Number & " - " & Err.Description & ".", vbCritical
End Select
Exit Sub
..and use Instr() to find the positions of "AIRCRAFT MODEL" etc, and then count that many spaces over in the data lines to extract each set of data. If that doesn't make sense, forget it, it doesn't work, because when LineInput reads the data in, it takes out all of the repeating spaces!!Code:DATE AIRCRAFT MODEL TO/FROM/REMARKS DAY NIGHT INST. TOTAL
So how the heck can I read this file in? How does Notepad do it?
Puzzled Allen :eek
