S
Stephen Lynch
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.
My if statements are wrong see below:
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, 3) <> "Header3" Then
Print #F4, st
Else
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
I want this in File1:
Bill
Jane
Mary
I want this in File2:
Jones
Smith
Janus
I want this in File3:
1
2
3
Here's my code. It saves the files but prints everything:
Public Sub SplitBuildFile()
Dim F1 As Integer
Dim F2 As Integer
Dim fInput As String
Dim fOutput1 As String
Dim fOutput2 As String
Dim fOutput3 As String
Dim st As String
fInput = "C:\test1.txt"
fOutput1 = "C:\position.txt"
fOutput2 = "C:\secdesc.txt"
fOutput3 = "C:\customer.txt"
If Len(Dir(fOutput1)) > 0 Then Kill fOutput1 'make sure it doesn't exist
already
F1 = FreeFile
Open fInput For Input As #F1
F2 = FreeFile
Open fOutput1 For Output As #F2
F3 = FreeFile
Open fOutput2 For Output As #F3
F4 = FreeFile
Open fOutput3 For Output As #F4
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, 3) <> "Header3" Then
Print #F4, st
Else
Close #F1
Close #F2
Close #F3
Close #F4
End If
End If
End If
Wend
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.
My if statements are wrong see below:
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, 3) <> "Header3" Then
Print #F4, st
Else
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
I want this in File1:
Bill
Jane
Mary
I want this in File2:
Jones
Smith
Janus
I want this in File3:
1
2
3
Here's my code. It saves the files but prints everything:
Public Sub SplitBuildFile()
Dim F1 As Integer
Dim F2 As Integer
Dim fInput As String
Dim fOutput1 As String
Dim fOutput2 As String
Dim fOutput3 As String
Dim st As String
fInput = "C:\test1.txt"
fOutput1 = "C:\position.txt"
fOutput2 = "C:\secdesc.txt"
fOutput3 = "C:\customer.txt"
If Len(Dir(fOutput1)) > 0 Then Kill fOutput1 'make sure it doesn't exist
already
F1 = FreeFile
Open fInput For Input As #F1
F2 = FreeFile
Open fOutput1 For Output As #F2
F3 = FreeFile
Open fOutput2 For Output As #F3
F4 = FreeFile
Open fOutput3 For Output As #F4
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, 3) <> "Header3" Then
Print #F4, st
Else
Close #F1
Close #F2
Close #F3
Close #F4
End If
End If
End If
Wend