Almost no one in the world
cares what a SLOC (Source Line of Code) is except people who try to
"measure" software in order to guess how long it might take to
create, how many people should be involved, and how much it will
cost. And those people happen to the the people who buy the software
that the company I work for produces. It is especially helpful in
estimating LARGE software projects comprised of many parts and modules,
based on code counts, "function points," or historical estimates
and comparisons. Although we distribute a tool for estimating a
broad range of code according to a variety of metrics, we also had a small
C-based console program for counting C and C++ source lines of code laying
around that we give to customers who want it. Unfortunately, it has
no graphical user interface. I thought it might be a fun exercise to
hone my Excel VBA skills by turning it into an Excel macro application,
which wasn't hard, except for the amount of time that it took. First
the code parser needed to be turned into a VBA module. A dialog had
to be created for reading folders and listing files. Selecting
directories had to be done using the Windows API Find Folders dialog,
which requires replicating the Windows SHBrowseForFolder API functionality in
VBA (the web site vbapi.com is especially helpful in this matter). And
getting file names requires using the Windows Scripting Host File System
The result is probably not all
that useful software given other tools out there so much as it shows how
MUCH can be done with Excel VBA if you set your mind to it. Of
course, if anyone wants this as an Excel Addin, I can configure it as
one, but in this case, not for free. But my guess is that most
likely it will remain merely an example of my programming skills, here
on the web site.
The Codecount application the
1. Ability to browse to any
directory using the Windows Find Folder dialog.
2. The ability to select any
number of files in the directory, filtered by *.C, *.CPP or *.H
type. The "Include File Types" filters are applied only to
the files selected in the dialog's file listing. If no files are
selected, all files in the directory are counted.
3. The ability to drill down
into a directory tree and count ALL *.C, *.CPP, or *.H files. Since
the results are listed in an Excel workbook, and you can extract subsets
of files in Excel, it didn't seem worthwhile to me to create a complicated
feature that allowed users to build a selective array of files across
their computer before using the Count button.
4. The ability to display the
results in the current sheet, overwriting any count that may have already
been done, or the ability to place the listing and count in a new sheet of
5. The ability of the user to
browse among the count sheets that have been created by the application.
5. When you press the Count
button, the application gives an immediate popup of the total SLOC count
of the files you have selected.
6. Then it lists files in an
Excel worksheet while remaining open to do further counts.