Private Sub Command1_Click()
Dim intff As Integer
Dim strAll() As String
intff = FreeFile
Open "D:\Testing\ENC Project\Setting\Sample.txt" For Input As #intff
strAll = Split(Input(LOF(intff), #intff) & vbCrLf, "START")
Close #intff
end sub
so far, i just doing the code above. i don't know how to write code when meet "START 129, S", then get the data from next line and stop until meet "STOP".After that, save the data which have been extract to a new text file.
Also look at the Instr Function to assist. The split function is not goint to help you here unless you just use it to fill an array with the lines of the file.
Open "D:\Testing\ENC Project\Setting\Sample.txt" For Input As #intff
intFOut = FreeFile()
Open "D:\Testing\ENC Project\Setting\SampleExtract.txt" For Output as #intFOut
Do Until EOF(intff)
Line Input #intff,strLine
If Not (strLine Like "START*" or strLine Like "STOP*") Then
Print #intFOut, strLine
End If
Loop
Close #intff
Close #intFOut
the code above just take out the "start" line and "stop" line.but, what i want is only need the value between the " START 129, S,...."line and "stop" line.
the result i want to get from "sample.txt" and save as another file is like below.
100.72022000 4.01296000;-1.2
100.67719000 4.01361000;1.5
100.65643000 4.01546000;7
100.63092000 4.01437000;8.5
100.63654000 3.99852000;9.8
100.05062000 3.69064000;49
100.22346000 2.88787000;43
100.18942000 2.91320000;39
100.23730000 2.92678000;25
101.05651000 3.39117000;5.6
99.71389000 3.85145000;35
99.81780000 3.88552000;42
You're question is unclear. Are you referring to that "header" information in the file? You just want to start outputting what's after that between start and stop?
How about this:
vb Code:
Dim intff As Integer
Dim intFOut as Integer
Dim strLine As String
Dim blnOutputOn As Boolean
intff = FreeFile()
Open "D:\Testing\ENC Project\Setting\Sample.txt" For Input As #intff
intFOut = FreeFile()
Open "D:\Testing\ENC Project\Setting\SampleExtract.txt" For Output as #intFOut
I think you need to loop when you get to a START and exit it when you get to a STOP. Also this code caters for the specific text you specified at the begining of the thread. You can change it to the name of a variable and pass values of your choice into.
Code:
Dim iInput As Integer
Dim iOutput As Integer
Dim sLine As String
iInput = FreeFile
Open "c:\sample.txt" For Input As #iInput
iOutput = FreeFile
Open "c:\sampleout.txt" For Output As #iOutput
Do Until EOF(iInput)
Line Input #iInput, sLine
If InStr(sLine, "START 129, S") Then
Do While Not EOF(iInput)
Line Input #iInput, sLine
If InStr(sLine, "STOP") Then
Exit Do
Else
Print #iOutput, sLine
End If
Loop
End If
Loop
Close #iInput
Close #iOutput