-
I am using the following code to loop through three files and process the data from each. I don't want to change the core functionality of this code.
Open sSummaryFileName For Append As #iSummFile
For count = 1 To 3
iTextFile = FreeFile
Open sFilename(count) For Input As #iTextFile
'Opens First Input File
Print #iSummFile, sHeader(count)
'Prints Header in Output File
Do Until EOF(iTextFile)
m_sReadString iTextFile
'Read in each Line and format
m_sWriteString iSummFile
'Write the formatted line to the Output File
Loop
Close #iTextFile
Next count
Close #iSummFile
As You can See I loop through each file at a time and then deal with the contents of each file.
My problem is as follows:
I print a header into iSummFile which changes for each of the three text file i am reading. If one of these files doesn't exist I still want the code to print a header into my final file. In other words if a file doesnt exist i only want to print the header before moving on to the next file and processing the data.
-
You will be printing the header no matter what, so print these first.
Then check to see if the file exists using the Dir$() function. If the file exists then carry on as noraml, else it will skip the file.
Code:
Open sSummaryFileName For Append As #iSummFile
For Count = 1 To 3
iTextFile = FreeFile
'print the headers no matter what
Print #iSummFile, sHeader(Count)
'if the file exists then open it and read / write
If Dir$(sFilename(Count)) <> "" Then
'Opens First Input File
Open sFilename(Count) For Input As #iTextFile
Do Until EOF(iTextFile)
m_sReadString iTextFile
'Read in each Line and format
m_sWriteString iSummFile
'Write the formatted line to the Output File
Loop
Close #iTextFile
End If 'If Dir$(sFilename(Count)) <> "" Then
Next Count
Close #iSummFile
-
Cheers
Your the Boy!
Thanks
Iceman
code: