How to display second line if the first line in text file is meet the condition
-
Dear All, Would you please tell me how to display second line if the first line in text file is meet the condition. I am using VB.NET. I would appreciate your helps very much,
You open the file, read the first line compare it to the condition, if it passses then you display the second line. What part is giving you problems? -------------------------------------------------------- My portfolio & development blog Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!
-
You open the file, read the first line compare it to the condition, if it passses then you display the second line. What part is giving you problems? -------------------------------------------------------- My portfolio & development blog Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!
Dear CWIZO, Here is my code below, with this code, I can read how many lines that met the condition, but I can not read the second line. Can you help me out. I would appreciate your potential helps very much,
Private Sub BtnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSend.Click Dim Start As String = "Start" Dim intTotalCount As Integer intTotalCount = CountStringInFile(strFile, Start) **<--HERE, I CAN READ HOW MANY LINE MET THE CONDITION** end Sub Private Function CountStringInFile(ByVal FilePath As String, ByVal StringToLookFor As String) As Integer Dim strContent As String = "" 'Get a StreamReaderclass that can be used to read the file Dim objStreamReader As StreamReader Dim intCount As Integer Dim intCountahead As Integer = 1 objStreamReader = File.OpenText(FilePath) While objStreamReader.Peek <> -1 strContent = objStreamReader.ReadLine intCount += CountLineByLine(strContent, StringToLookFor) End While 'Close the stream objStreamReader.Close() objStreamReader = Nothing Return intCount End Function Private Function CountLineByLine(ByVal vstr As String, ByVal strToSearch As String) As Integer Dim intIndex As Integer Dim intCount As Integer = 0 intIndex = InStr(vstr, strToSearch) While intIndex > 0 intCount += 1 intIndex = InStr(intIndex + 1, vstr, strToSearch) End While Return intCount End Function