jtrowbridge
12-13-2007, 12:22 PM
I'm having performance issues when I'm reading from a particularly large text file (14Mb). When the program gets to the Line Input #1 section of the code it takes VB about 45 seconds to access the text file and figure out what line it is currently reading from.
The data in the txt is comma delimited and structured like so:
String_A, An_Integer, A_Double
String_B, An_Integer, A_Double
String_C, An_Integer, A_Double
...
All I'm trying to read is the string before the first comma, so that's why the InStr function comes into play and why I'm using 'Line Input'.
Does anyone know of a more efficient way to read from a large set of data? The only kind of file reading I know how to use is the 'Open For Input' function.
Here's the code:
---------------------------
Dim Data_Line As String
Dim File_Name As String
Dim Curve_Name() As String
Dim FirstCommaPosition As Integer
File_Name = "C:\test\CurveSummary.txt"
n = 0
ReDim Curve_Name(n)
Open File_Name For Input As #1
Do While Not EOF(1)
Line Input #1, Data_Line 'Takes way to long to access here...
FirstCommaPosition = InStr(Data_Line, Chr(44))
Curve_Name(n) = Left(Data_Line, FirstCommaPosition - 1)
n = n + 1
ReDim Preserve Curve_Name(n)
Loop
Close #1
--------------------------
Thanks in advance!
:doh:
The data in the txt is comma delimited and structured like so:
String_A, An_Integer, A_Double
String_B, An_Integer, A_Double
String_C, An_Integer, A_Double
...
All I'm trying to read is the string before the first comma, so that's why the InStr function comes into play and why I'm using 'Line Input'.
Does anyone know of a more efficient way to read from a large set of data? The only kind of file reading I know how to use is the 'Open For Input' function.
Here's the code:
---------------------------
Dim Data_Line As String
Dim File_Name As String
Dim Curve_Name() As String
Dim FirstCommaPosition As Integer
File_Name = "C:\test\CurveSummary.txt"
n = 0
ReDim Curve_Name(n)
Open File_Name For Input As #1
Do While Not EOF(1)
Line Input #1, Data_Line 'Takes way to long to access here...
FirstCommaPosition = InStr(Data_Line, Chr(44))
Curve_Name(n) = Left(Data_Line, FirstCommaPosition - 1)
n = n + 1
ReDim Preserve Curve_Name(n)
Loop
Close #1
--------------------------
Thanks in advance!
:doh: