Nice Loop!!

Leeus

Well-known member
Joined
Dec 23, 2002
Messages
50
Code:
txtfilename.Text = txttype.Text & txtdate.Text & ".LOG"
        Dim filelocation As String = "c:\mail\Log\" & txtfilename.Text
        Dim sr As New System.IO.StreamReader(filelocation)
        Dim Line As String
        Dim vals() As String
        Dim threads() As String

        Do
            Line = sr.ReadLine()
            If Line Is Nothing Then Exit Do
            vals = Line.Split(" ")
            If InStr(Line, txtsearch.Text) > 0 Then
                If Len(vals(7)) = 5 Then
                    txtmessage.Text += vals(7) & vbCrLf
                    txtmessage.Text = Line

I want action here!!!
                End If
            End If
        Loop While Not Line Is Nothing
        sr.Close()
This works fine so far and retrieves a value in vals(7), at that point I want to go back through the message and find all lines containing that value. Bear in mind I can find several values for vals(7).

I cant think of a way of doing it???
 
i wouldnt bother with a Do Loop , try While Not sr.Peek. heres a quick example...
Code:
        txtfilename.Text = txttype.Text & txtdate.Text & ".LOG"
        Dim filelocation As String = "path to your file here!" eg:... "c:\mail\Log\" & txtfilename.Text
        Dim sr As New IO.StreamReader(New IO.FileStream(filelocation, IO.FileMode.OpenOrCreate))
        Dim vals() As String
        Dim strString As String
        While Not sr.Peek
            vals = sr.ReadLine.Split(" ")
            For Each strString In vals
                If strString = txtsearch.Text Then
                    If strString.Length = 5 Then
                        /// do stuff here.
                    End If
                End If
            Next
        End While
        sr.Close()
 
Back
Top