Capoerista
Programmer
Hi All,
I've inherited support of a VB application which is having performance problems processing large text files. I have narrowed down the problem to the for loop section. The aim is to read in an rtf file, then output a copy of the file with rightmost blanks stripped.
The routine is
For context the code that calls this routine is
The input file is approx 3Mb and takes about 20 mins on a 2Ghz PC with 256Mb memory to get through this routine. Is the main problem doing a len on an increasingly large string? Any pointers on possible improvements would be greatly appreciated.
Cheers
Ade
P.S. I'm not sure why the loop is going backwards through the array.
I've inherited support of a VB application which is having performance problems processing large text files. I have narrowed down the problem to the for loop section. The aim is to read in an rtf file, then output a copy of the file with rightmost blanks stripped.
The routine is
Code:
Function TrimTrailingBlankLines(Indat As String) As String
Dim Res As String
Dim lins, ln, Lin
Debug.Print "TrimTrailing... split"
lins = Split(Trim(Indat), vbCrLf)
Debug.Print "TrimTrailing... for"
For ln = UBound(lins) To 0 Step -1
Lin = lins(ln)
If Trim(left(Lin, 4)) = "____"
Then
Lin = Space(Len(Lin))
End If
If Len(Res) = 0 Then
If Trim(Lin) <> "" Then
Res = Lin
End If
Else
Res = Lin & vbCrLf & Res
End If
Next
Debug.Print "... TrimTrailing"
TrimTrailingBlankLines = Res
End Function
For context the code that calls this routine is
Code:
Debug.Print "Read form frmEmail_2_OTC"
Load frmEmail_2_OTC
Set TS = fso.OpenTextFile(INPUT_FILE, ForReading)
frmEmail_2_OTC.rtfTemp.TextRTF = TS.ReadAll
TS.Close
Debug.Print "close form"
NewIn = fso.GetParentFolderName(INPUT_FILE) & "\OrigRTF_" & fso.GetFileName(INPUT_FILE)
If fso.FileExists(NewIn) Then
Kill NewIn
End If
Name INPUT_FILE As NewIn
'Name Run_File as
Set TS = fso.OpenTextFile(INPUT_FILE, ForWriting, True)
Debug.Print "Trim Blanks"
TS.Write TrimTrailingBlankLines(Trim(frmEmail_2_OTC.rtfTemp.Text)) & vbCrLf
TS.Close
Debug.Print "End Trim Blanks"
The input file is approx 3Mb and takes about 20 mins on a 2Ghz PC with 256Mb memory to get through this routine. Is the main problem doing a len on an increasingly large string? Any pointers on possible improvements would be greatly appreciated.
Cheers
Ade
P.S. I'm not sure why the loop is going backwards through the array.