I have the following code in a VB project that loops through each record in a text file and edit each record as necessary, in a new text file:
The code works as intended however it runs very slowly, because most of the text files are 300,000+ records in length. It usually takes over three minutes to run and I have a fast machine. And the problem is this has to be done to not just one but many files.
Is there a better way to accomplish the same thing, only faster?
Thanks,
Kevin
Code:
Open myOldFileName For Input As #1
Open myNewFileName For Output As #2
Do Until VBA.EOF(1)
Line Input #1, str1
If Left(str1, 2) = "11" Then
If (Mid(str1, 30, 8) = "71277570" Or Mid(str1, 30, 8) = "71277571" Or Mid(str1, 30, 8) = "71277572" Or Mid(str1, 30, 8) = "71277573" Or Mid(str1, 30, 8) = "71277574") Then
Print #2, Application.WorksheetFunction.Replace(str1, 41, 4, "9999")
Else
Print #2, str1
End If
Else
Print #2, str1
End If
Loop
Close #2
Close #1
The code works as intended however it runs very slowly, because most of the text files are 300,000+ records in length. It usually takes over three minutes to run and I have a fast machine. And the problem is this has to be done to not just one but many files.
Is there a better way to accomplish the same thing, only faster?
Thanks,
Kevin