If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Dim FILE_NAME As String = "C:\text.txt"
Dim textdelimiter As String
Dim file_line As String
Dim intCol As Int16
Dim X As Integer
Dim oWriter As System.IO.StreamWriter
textdelimiter = " "
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objReader As New System.IO.StreamReader(FILE_NAME)
TextBox1.Text = objReader.ReadToEnd
Do While objReader.Peek() > -1
TextLine = TextLine & objReader.ReadLine() & vbNewLine
Dim aline() = Split(TextLine, " ")
TextBox2.Text = TextLine
' Loop through column values
For X = 0 To aline.Length - 1
' If this is the CD column, then set the column indicator
' for the lines that follow.
If (aline(X) = "cd") Then
' Open the destination
oWriter = New System.IO.StreamWriter("C:\p.txt")
' get the CD column number
intCol = X
Exit For
End If
Next
' If we've set the CD column already, we must be into the
' data section...
If intCol <> 0 Then
' Write just the CD column data value
oWriter.Write(aline(intCol) & vbCrLf)
End If
Loop
' Close the writer
oWriter.Close()
' Close the reader
objReader.Close()
End If

With VS.NET closed, can you delete the file? It might still be held open by a process that got left when the program crashed. This would require a reboot.

If you can delete it, then step through the program and see what is going on. It would seem that the line "oWriter = New System.IO.StreamWriter("C:\p.txt")" is being called twice, but I can't imagine why...