wvandenberg
Technical User
I am attempting to read a text file into a multi-dimensional array. I am able to read the file into a one-dimensional array (each line is one element in the array) However, I now need to split each line into it's own array and then store that into an array. Here is an example of the text file:
12/01/2003 13:32:45 21.67 0.005 8.12 8.10 8.326
12/01/2003 13:33:00 21.67 0.005 8.12 8.10 8.312
12/01/2003 13:33:15 21.67 0.005 8.12 8.11 8.325
12/01/2003 13:33:30 21.67 0.005 8.12 8.11 8.311
12/01/2003 13:33:45 21.67 0.005 8.12 8.11 8.331
12/01/2003 13:34:00 21.68 0.005 8.12 8.09 8.320
So I would like the multi-dimensional array to store it something like this:
arrValues(0,0) would hold 12/01/2003
arrValues(4,6) would hold 8.331
arrValues(5,1) would hold 13:34:00 etc.
Here is the code I have so far:
Dim fsoFile As FileSystemObject
Dim tsoText As TextStream
Dim i As Integer
Dim arrTextLines()
Dim strLine As String
Set fsoFile = New FileSystemObject
Set tsoText = fsoFile.OpenTextFile(strFile, ForReading)
Set rsTxtStrm = New Recordset
i = 0
Do Until tsoText.AtEndOfStream
strLine = tsoText.ReadLine
'The following I statement skips any header information that may be in the file
If Left(strLine, 2) = "**" _
Or Left(strLine, 2) = " " _
Or Left(strLine, 2) = "==" _
Or Left(strLine, 2) = "--" Then
Else
ReDim Preserve arrTextLines(i)
arrTextLines(i) = strLine
i = i + 1
End If
Loop
tsoText.Close
As I mentioned earlier, the code above will only read the text file into a one-dimensional array (line by line) and I need it read into a multi-dimensional array (line by line and value by value). Just so you know, there are consecutive delimiters (2-3 spaces because it a fixed width file) between the numerical values in each line. I do have a function that is similar to the Split() function but it will ignore consecutive delimiters if it is needed (I haven't included it here). Also, there will only ever be a total of 8 columns (they didn't all fit neatly so I chopped two for this post) but the number of rows will vary.
If anyone has any suggestions I would be really grateful.
Thanks in Advance,
Wendy
12/01/2003 13:32:45 21.67 0.005 8.12 8.10 8.326
12/01/2003 13:33:00 21.67 0.005 8.12 8.10 8.312
12/01/2003 13:33:15 21.67 0.005 8.12 8.11 8.325
12/01/2003 13:33:30 21.67 0.005 8.12 8.11 8.311
12/01/2003 13:33:45 21.67 0.005 8.12 8.11 8.331
12/01/2003 13:34:00 21.68 0.005 8.12 8.09 8.320
So I would like the multi-dimensional array to store it something like this:
arrValues(0,0) would hold 12/01/2003
arrValues(4,6) would hold 8.331
arrValues(5,1) would hold 13:34:00 etc.
Here is the code I have so far:
Dim fsoFile As FileSystemObject
Dim tsoText As TextStream
Dim i As Integer
Dim arrTextLines()
Dim strLine As String
Set fsoFile = New FileSystemObject
Set tsoText = fsoFile.OpenTextFile(strFile, ForReading)
Set rsTxtStrm = New Recordset
i = 0
Do Until tsoText.AtEndOfStream
strLine = tsoText.ReadLine
'The following I statement skips any header information that may be in the file
If Left(strLine, 2) = "**" _
Or Left(strLine, 2) = " " _
Or Left(strLine, 2) = "==" _
Or Left(strLine, 2) = "--" Then
Else
ReDim Preserve arrTextLines(i)
arrTextLines(i) = strLine
i = i + 1
End If
Loop
tsoText.Close
As I mentioned earlier, the code above will only read the text file into a one-dimensional array (line by line) and I need it read into a multi-dimensional array (line by line and value by value). Just so you know, there are consecutive delimiters (2-3 spaces because it a fixed width file) between the numerical values in each line. I do have a function that is similar to the Split() function but it will ignore consecutive delimiters if it is needed (I haven't included it here). Also, there will only ever be a total of 8 columns (they didn't all fit neatly so I chopped two for this post) but the number of rows will vary.
If anyone has any suggestions I would be really grateful.
Thanks in Advance,
Wendy