Tracy Martin is the winner of an annual subscription to Code of the Week for submitting this weeks source code.
For the next month we are offering a free annual subscription to anyone that submits source code for an issue which gets published. If you have some useful source code that would be valuable for our members, fill out the form at http://www.codeoftheweek.com/submissions.html
Please make sure all source code is tested and is in working condition. We are looking for all types of source from database access routines to API calls to graphics routines. We are not looking for one or two lines tricks at this time (this will be a future offering) . The source code should be at least 10 or 15 lines of long, preferably longer. It should be commented or at least readable by the average programmer.
If you are currently a member of Code of the Week we will extend your subscription an additional year.
Download a free copy of NetMon - Your Internet Performance Monitor at http://www.codeoftheweek.com/netmon/index.html
In this issue we show a very fast way to search for files.
This source code is designed for VB 4.0 32-bit and up. Questions? Email us at questions@codeoftheweek.com.
The cFindFiles class module was written by Tracy Martin with some small modifications by C&D Programming Corp. It contains a couple of methods for getting files and information about files it has found.
If you have any questions about using this class, let us know at questions@codeoftheweek.com
Public Function FindFile(ByVal pstrName As String) As Boolean
This is the start of the search routine. You would call this with a parameter such as "e:\temp\*.xls" to find all files with the extension xls. It will return True if a file was found and False if it was not found. After calling this function you can use any of the Properties listed below to get additional information provided it returned True.
Public Function FindNextFile() As Boolean
This routine needs to be called until it returns False in order to retrieve all the matching files. After calling this function you can use any of the Properties listed below to get additional information provided it returned True.
Completes one search and allows you to begin another.
See each function/properties for details.
The below sample describes how to use the cFindFiles class. It will show how many files are located in the E:\TEMP directory.
Option Explicit Private Sub FindTest() Dim Fnd As cFindFiles Dim bContinue As Boolean Dim lCount As Long Set Fnd = New cFindFiles bContinue = Fnd.FindFile("e:\temp\*.*") While bContinue lCount = lCount + 1 bContinue = Fnd.FindNextFile Wend MsgBox "Found " & lCount & " matching files." End Sub
To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address: http://www.codeoftheweek.com/membersonly/bi/0080.html