Hello everyone.
I have a text file eg.
line1
line2
line3
line4
line5
I want to read these lines to excel cells a1,b1,c1 ect until it reaches the words "Date: " then start writing a2,b2,c2 ect. this is the code i have.
' Create an instance of StreamReader to read from a file.
Dim OpenFileDialog As OpenFileDialog = New OpenFileDialog
OpenFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
OpenFileDialog.Title = "Open File"
OpenFileDialog.ShowDialog()
Dim sr As StreamReader = New StreamReader(OpenFileDialog.FileName)
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
Console.WriteLine(line)
If line = "Date: " Then
Do
line = sr.ReadLine()
Loop Until line = "Service Order "
End If
Loop Until line Is Nothing
sr.Close()
Catch ex As Exception
MsgBox("Please select a file", MsgBoxStyle.OkOnly, "Error")
End Try
I have a text file eg.
line1
line2
line3
line4
line5
I want to read these lines to excel cells a1,b1,c1 ect until it reaches the words "Date: " then start writing a2,b2,c2 ect. this is the code i have.
' Create an instance of StreamReader to read from a file.
Dim OpenFileDialog As OpenFileDialog = New OpenFileDialog
OpenFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
OpenFileDialog.Title = "Open File"
OpenFileDialog.ShowDialog()
Dim sr As StreamReader = New StreamReader(OpenFileDialog.FileName)
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
Console.WriteLine(line)
If line = "Date: " Then
Do
line = sr.ReadLine()
Loop Until line = "Service Order "
End If
Loop Until line Is Nothing
sr.Close()
Catch ex As Exception
MsgBox("Please select a file", MsgBoxStyle.OkOnly, "Error")
End Try