Visual Basic Code of the Week (COTW)
Issue #80
Online Version at (paid subscribers only)
All content and source code is Copyright (c) 1999 by C&D Programming Corp. No part of this issue can be reprinted or distributed in any manner without express written permission of C&D Programming Corp.


Tracy Martin is the winner of an annual subscription to Code of the Week for submitting this weeks source code.

Get your Free Year of Code of the Week!!!

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

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.

Cool Software

Download a free copy of NetMon - Your Internet Performance Monitor at

In this Issue

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


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


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.


Public Sub FindClose()

Completes one search and allows you to begin another.



See each function/properties for details.

Sample Usage

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
    MsgBox "Found " & lCount & " matching files."
End Sub

Source Code

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:

This document is available on the web

Paid subscribers can view this issue in HTML format. There is no additional source or information in the HTML formatted document. It just looks a little better since we have included some HTML formatting. Just point your browser to link at the top of this document.

Other links

Contact Information

C&D Programming Corp.
PO Box 20128
Floral Park, NY 11002-0128
Phone or Fax: (212) 504-7945