Results 1 to 5 of 5

Thread: search file

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Location
    Federal Way, WA, USA
    Posts
    13
    I'm making a program that will search if text1.text is in a file. and if it is it will print it in a textbox called textbox. Please help me and I would appreciate it if it was detailed.

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    here's one way:

    Code:
    Private Sub Command1_Click()
    
    TextBox.Text = SearchFile(filename, Text1.Text)
    
    End Sub
    
    Private Function SearchFile(filename As String, SearchText As String) As String
    Dim fnum As Byte
    Dim strTemp As String
    
    fnum = FreeFile
    Open filename For Binary As fnum
      strTemp Space(LOF(nfum))
      Get #fnum, , strTemp
    Close fnum
    
    If InStr(strTemp, SearchText) > 0 Then
      SearchFile = strTemp
    End If
    
    
    End Function
    Mark
    -------------------

  3. #3
    Lively Member
    Join Date
    Jan 2000
    Location
    North Yorkshire
    Posts
    102
    Hi,
    I have a similar problemm, except that I need to search in a file that could be 50Mb. Does anybody have a nice fast way of doing this rather than creating a 50Mb string !

    cheers

    Andy

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Try to get parts of it, not the whole file.

  5. #5
    Lively Member
    Join Date
    Jan 2000
    Location
    North Yorkshire
    Posts
    102
    Hi,
    Thanks for the info. I'd started down the wrong track in loading the data as a byte array. I've switched to a binary read with a reasonable size string (64K) and using Instr to find the locations and it now works very well.

    thanks for the info

    cheers

    Andy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width