Hey Everyone,
I'm having a hardtime speeding up the processing of a very large textfile (~100 Meg or so). I've made caution to be very diligent using the redim preserve calls, and yet the function still takes 5 minutes or so to run. The textfile is basically sub reports which i'm trying to parse out. I only have access to the large file. What is a person to do. Is VBA just that slow? Here is the code, the "Report" object is a class I created. Most of the reports are just a couple hundred lines, so thats why I choose 1000 for the ubound:
Public Function GetPages(originalFilePath As String) As Collection
Dim myReport As report
Dim reportPageCollection As Collection
Dim startLine As Long
Dim endLine As Long
Dim fso As FileSystemObject
Dim file As textStream
Dim lineStr As String
Dim index As Long
Dim lines() As String
Set fso = New FileSystemObject
Set reportPageCollection = New Collection 'initialize the collection
Set file = fso.OpenTextFile(originalFilePath, ForReading)
ReDim lines(0 To 1000)
lineStr = file.ReadLine 'skip the first line so the loop doesnt add a blank report
lines(0) = lineStr
index = 1
Do Until file.AtEndOfLine 'loop through from the startline to find the end line
lineStr = file.ReadLine
If lineStr Like "1JOBNAME:*" Then 'next report, so we want to return an array of the single line
'load this page into our report page collection for further processing
Set myReport = New report
myReport.setDataLines = lines() 'Fill in 'ReportPage' Array
reportPageCollection.Add myReport 'add our report to the collection
'set up array for new report
ReDim lines(0 To 1000)
index = 0
lines(index) = lineStr
index = index + 1
Else
'============================ store into array
If index = UBound(lines) Then
ReDim Preserve lines(0 To UBound(lines) + 1000)
lines(index) = lineStr
index = index + 1
Else
lines(index) = lineStr
index = index + 1
End If
'============================
End If
Loop
file.Close
Set fso = Nothing
Set GetPages = reportPageCollection
End Function
Any Help is appreciated. Thanks!