Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Jan 16, 1998

Searching Multiple Files

Question:
I use VB5 and I'm trying to search through multiple files for a string and open this file in a TextBox. How can I do this?

Answer:
There really isn't a quick and easy way to do this, unfortunately. The basic steps are as follows:

  1. Create a list of the files to be searched. You can use the Dir function to return a list of files in a particular directory.
  2. Open each file in order and look for the piece of text in the file. The code to do this is fairly simple:
       Dim sBuffer As String
       Const sSearchString = "REM"
       
       Open "C:\Autoexec.bat" For Input As #1
       sBuffer = Input$(LOF(1), 1)
       Close #1
       
       If InStr(1, sBuffer, sSearchString, vbTextCompare) > 0 Then
          MsgBox "Found string in file"
       End If
    
  3. The InStr function returns the position at which the string you wanted was found in the buffer. You can then put it into a TextBox control.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date