Find Next function for search with Like operator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mustakbal
    New Member
    • Jul 2007
    • 25

    Find Next function for search with Like operator

    I am using this code to search with wild cards for strings in a text file. I wanted to improve the application by adding a "Find Next " button that will display the rest of the strings that the search initiated by the Function SearchString finds. For example the initial search for "*out" will result in displaying "doubt" in Lbltext1Caption and the debug.print would list more strings found at certain lines. How can I employ a second button that can progressively display the remainder of the strings found. I have tried and searched very hard for this with no luck, so any help will be greatly appreciated. This forum has been very helpful for me in the past and people here proved very knowledgeable. I know I am in the right place so please help!


    Code:
    Private Function SearchString() 
     
    Dim Fnum As Long, Buffer As String, LineNo As Long 
    index1 = (LineNo) 
    LineNo = -1 
    Fnum = FreeFile  
       
      filename = ("C:\windows\temp\file.txt") 
      thestring = TxtSearch.Text 
      
      Open filename For Input Access Read Shared As #Fnum 
         
      Do Until EOF(Fnum) 
        ' Retrieve one line of text from the file a string. 
        Line Input #Fnum, Buffer 
        LineNo = LineNo + 1 
         
         If LCase$(Buffer$) Like "*" & LCase$(thestring$) & "*" Then        
              
         = line_value1(index1) 
         
          Debug.Print "Found string at line: "; Format(LineNo) 
           End If 
           Loop 
           
      Close Fnum 
     
    End Function
Working...