J
Jim
..net newbie
I'm trying to read using TextFieldParser because my input file needs to
be parsed. Works fine. I can display the data in a msg box. Now I
want to write that data to a text file including a cr/lf at the end.
The trouble I'm having is converting currentRow to sting. The error I
get relates to the fact that its defined as an array and vb says it
can't convert it to text.
In the test code below (VB examples) the first commented line works.
The line after them doesn't and that's the one I want.
If there are better ways to do this please let me know.
==========================
Public Class frm_TextFieldParser
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Using MyReader As New
Microsoft.VisualBasic.FileIO.TextFieldParser("C:\278.txt")
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters("~")
Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentField As String
For Each currentField In currentRow
''=>MsgBox(currentField) <== works
My.Computer.FileSystem.WriteAllText("C://testfile.txt",
currentField, True) <== doesn't
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
End Sub
End Class
I'm trying to read using TextFieldParser because my input file needs to
be parsed. Works fine. I can display the data in a msg box. Now I
want to write that data to a text file including a cr/lf at the end.
The trouble I'm having is converting currentRow to sting. The error I
get relates to the fact that its defined as an array and vb says it
can't convert it to text.
In the test code below (VB examples) the first commented line works.
The line after them doesn't and that's the one I want.
If there are better ways to do this please let me know.
==========================
Public Class frm_TextFieldParser
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Using MyReader As New
Microsoft.VisualBasic.FileIO.TextFieldParser("C:\278.txt")
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters("~")
Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentField As String
For Each currentField In currentRow
''=>MsgBox(currentField) <== works
My.Computer.FileSystem.WriteAllText("C://testfile.txt",
currentField, True) <== doesn't
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
End Sub
End Class