Here's some code to get you started.
To loop through, open and read the selected files:
Code:
Dim sr As System.IO.StreamReader
Dim ThisLine as string = ""
For Each FileName As String In OpenFileDialog1.FileNames
sr = New System.IO.StreamReader(FileName)
'read the file line by line
Do While sr.Peek <> -1
'do stuff with lines read
ThisLine = sr.ReadLine
Loop
Next
To display the data in a DataGridView, you could create a class for each header type, like so:
Code:
Public Class Header1
Dim sField1 As String
Dim sField2 As String
Public Property Field1() As String
Get
Return sField1
End Get
Set(ByVal value As String)
sField1 = value
End Set
End Property
Public Property Field2() As String
Get
Return sField2
End Get
Set(ByVal value As String)
sField2 = value
End Set
End Property
End Class
Now, as you parse the files create new instances of the appropriate class and populate its properties. Assign those class instances to an arry of that class type;
Code:
Dim Header1Array() As Header1
For Each FileName As String In OpenFileDialog1.FileNames
sr = New System.IO.StreamReader(FileName)
If Header1Array Is Nothing Then
ReDim Header1Array(0)
Else
ReDim Preserve Header1Array(Header1Array.Length)
EndIf
'read the file line by line
Do While sr.Peek <> -1
'do stuff with lines read
ThisLine = sr.ReadLine
Header1Array(Header1Array.Length - 1) = New Header1
Header1Array(Header1Array.Length - 1).Field1 = ThisLine.Substring(0, 3)
Header1Array(Header1Array.Length - 1).Field2 = ThisLine.Substring(3, 6)
'note: these are just examples, what you do will be different
Loop
Next
Finally, you can assign the array of objects to a DataGridView, which will display them.
Code:
DataGridView1.DataSource = Header1Array
DataGridView1.Columns(0).HeaderText = "Column 1"
DataGridView1.Columns(0).HeaderText = "Column 2"
I hope this gets you going toward a solution. There are other ways to display the data in a grid (e.g., in-memory datatable), but you will still need to use the System.IO.StreamReader to read the files.
I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
Arrrr, mateys! Ye needs ta be preparin' yerselves fer
Talk Like a Pirate Day!