Well, I have successfully coded my unformatted text data. I used comma as a delimiter and if I am posting it here so that it can help students like me.
Try
Using Reader As New TextFieldParser(Application.StartupPath & "\data.txt")
Reader.TextFieldType = FieldType.FixedWidth
Reader.SetFieldWidths(20, 20, 1, 2)
Dim currentRow As String()
While Not Reader.EndOfData
Try
currentRow = Reader.ReadFields()
Dim oWrite As New System.IO.StreamWriter(Application.StartupPath & "\FormattedData.txt")
For Each newString In currentRow
oWrite.Write(newString & ",")
Next
oWrite.WriteLine()
oWrite.Close()
Catch ex As Exception
End Try
End While
End Using
Catch ex As Exception
End Try
Now I have a question too: How can I omit the last comma from the output while importing to access database?
The easiest way to do this (that I have found) is to write the comma for the last record on the next pass, but don’t do it on the first loop: