Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

source code for seaching in vb5

Posted on 1999-07-22
9
Medium Priority
?
257 Views
Last Modified: 2008-03-06
Can anyone give me a hand to write a seaching program in visual basic?
0
Comment
Question by:chkwah
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 

Expert Comment

by:Marktalbot
ID: 1526558
Write a batch file taht redirects a dir statment to a file.
Then open that file and read the information line by line using line input util you find the information you  want.
0
 
LVL 5

Expert Comment

by:KDivad
ID: 1526559
Searching for files? In multiple folders? I have written some code that searches and returns all files in a folder and it's sub folders, interested?
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 1526560
Marktalbot.. and then a Pascal program to read the file the dir batch file returns.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 10

Expert Comment

by:viktornet
ID: 1526561
use FileFindFirst() and FileFindNext()

If you need more HANDm, hehe ;)), lemme know...

..-=ViKtOr=-..
0
 

Author Comment

by:chkwah
ID: 1526562
I need an example of the source code
0
 
LVL 10

Accepted Solution

by:
viktornet earned 200 total points
ID: 1526563
Here is an example for searching folders.... a few minors changes and you will get it to work for files...

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=338

..-=ViKtOr=-..
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 1526564
Here's code to list all files in a directory including subdirectories (if you want):

This function will return True if the listing was successful, false otherwhise.

Paramenters in:
   Path = the directory you want to search
   av_Array() = the array you want to fill with all the filenames
   Recursive = boolean value that is True if you want to search all subdirectories, false otherwhise
   x = Don't do anything with this, it's only used in recursive calling
   StartDir = Don't do anything with this either, it's only used in recursive calling
   IncludePaths = if you only want to get the filenames you set this to False but default value is True (you will get full pathnames)



Function ListFiles(ByVal Path As String, ByRef av_Array() As String, Recursive As Boolean, Optional ByRef x As Double = 0, Optional StartDir As Boolean = True, Optional IncludePaths As Boolean = True)

  Dim MyName  As String
  Dim MyDir() As String
  Dim MyDirNr As Integer
  Dim a       As Integer
 
  MyDirNr = 0
  ReDim MyDir(0)
  If (x = 0) Then
    ReDim av_Array(0)
    Path = sAddDirSep(Path)
  End If
 
  On Error GoTo ErrorHandler
 
  MyName = Dir$(Path + "*.*", vbDirectory + vbArchive + vbHidden + vbReadOnly + vbSystem)
   
  Do While MyName <> ""
    If MyName <> "." And MyName <> ".." Then
      If (GetAttr(Path & MyName) And vbDirectory) <> vbDirectory Then
        If (x Mod 10 = 0) Then
          ReDim Preserve av_Array(x + 10)
        End If
        x = x + 1
        If IncludePaths Then
          av_Array(x) = Path + MyName
        Else
          av_Array(x) = MyName
        End If
      Else
        ReDim Preserve MyDir(UBound(MyDir) + 1)
        MyDirNr = MyDirNr + 1
        MyDir(MyDirNr) = MyName
      End If
    End If
    MyName = Dir
  Loop
 
  If Recursive Then
    For a = 1 To MyDirNr
      If Not ListFiles(Path + MyDir(a) + "\", av_Array(), True, x, False, IncludePaths) Then GoTo ErrorHandler
    Next
  End If
  If StartDir Then ReDim Preserve av_Array(x)
  ListFiles = True
  Exit Function
 
ErrorHandler:
  ListFiles = False

End Function

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1526565
Just to mention.... in order to change the folder searching example to file searching, you simply have to check for faDirectory which is a constant, and if it is then you simypl recursivly call that function on the directory you've found... as simple as that. :)
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 1526566
Hmm i forgot the sAddDirSep function it's supposed to look something like this

Function sAddDirSep(Text as String) As String

  sAddDirSep = IIF(Right$(Text, 1) = "\", Text, Text & "\")

End Function

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question