I want to read fixed length files.
I know how to do this if I know the field lengths.
Using Reader As New Microsoft.VisualBasic.FileIO.TextFieldParser(filePath)
Reader.TextFieldType =
Microsoft.VisualBasic.FileIO.FieldType.FixedWidth
Reader.SetFieldWidths(8, 16, 16, 12, 14, 16) 'They are different in each file
Dim currentRow As String()
While Not Reader.EndOfData
Try
currentRow = Reader.ReadFields()
Dim currentField As String
For Each currentField In currentRow
MsgBox(currentField)
Next
Catch ex As Microsoft.VisualBasic.
FileIO.MalformedLineException
MsgBox("Line " & ex.Message &
"is not valid and will be skipped.")
End Try
End While
End Using
The problem is that I don't know the length of each field.
Is there a way to read the first line and get the Field lengths?