devxlogo

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.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Five Early Architecture Decisions That Quietly Get Expensive

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.