CodeItBetter Programming Another VB Programming Blog

How to search for a string in a text file if found, display that line to the user.

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
'Text File Handling - How to search for a string in a text file if found, display that line to the user.
Option Explicit
 
Sub Main()
    Call SearchForString("C:\Temp\SearchFile.txt", "Teststring")
End Sub
 
Public Sub SearchForString(ByVal strFileName As String, ByVal SearchString As String)
    Dim strLine As String
 
    Open strFileName For Input As #1    ' Open file for input.
    Do While Not EOF(1)    ' Loop until end of file.
        Input #1, strLine
        If InStr(strLine, SearchString) > 0 Then MsgBox strLine
    Loop
    Close #1    ' Close file.
End Sub
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.