View Full Version : Print Records Between Headers


slynch401k
07-15-2008, 01:51 PM
Ok, I just need a little advice. I have written code to extract part of a single file that has three headers and save the parts to three seperate files but I cannot seem to get the if statements right. My code saves the three files, so I only need help with the if statements or if there is a between statement.

What I want to do is say Print everything between @@Header1 and @@Header2 to File1, Print everything between @@Header2 and @@Header3 to File2, and print everything after @@Header3 to File3.


Here is what the file looks like, I am trying to separate by the headers:

@@Header1
Bill
Jane
Mary
@@Header2
Jones
Smith
Janus
@@Header3
1
2
3


While Not EOF(F1)
Line Input #F1, st
If Mid(st, 3) <> "HEADER1" Then
Print #F2, st
Else
If Mid(st, 3) = "HEADER2" Then
Print #F3, st
Else
If Mid(st, 27) = "HEADER3" Then
Print #F4, st

End If
End If
End If
Wend

Close #F1
Close #F2
Close #F3
Close #F4

slynch401k
07-15-2008, 05:14 PM
Found out how, used this instead of my if statements


Dim FCurrent as Integer
...
Do Until EOF(F1)
Line Input #F1, st
Select Case st
Case "@@Header1"
FCurrent = F2

Case "@@Header2"
FCurrent = F3

Case "@@Header3"
FCurrent = F4

Case Else
Print #FCurrent, st
End Select
Loop