VB6 code counter

Does VB6 have a lines of code counter utility?  If it doesn't have where can I get a free one?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

do you want to just count the number of lines in the code or make a line number at the front of each line?
VB6 has no code counter utility
I do not know of free one's, but there are several commercial tools like the Numega Tools
this is one of the EASIEST add-ins to write.  If all you want is the total lines of code in all of your modules, do this:

1)  Create a new project, using the Add-in template
2)  Write a function in the CONNECT designer:

public sub CountLines()
  dim cmp  as vbComponent
  dim lSum as long
  for each cmp in vbinstance.ActiveVBProject
    if not cmp.CodeModule is nothing then
      lsum = lsum + cmp.CodeModule.CountOfLines
    end if
  next cmp

  msgbox "Line Count: " & lsum
end sub

3)  in the AddinMenuHandler Click event call the function

If you'd like an add-in utility I wrote, and are willing to report bugs to me, email me at anthonyc4@yahoo.com


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!


Here is what you are looking for:

Option Explicit

Private Sub Command7_Click()
Dim Rad As String
Dim Property As String
Dim Value As String
Dim Filename As String
Dim ProjectDir As String
Dim ProjectFile As String
Dim LineCount As Long
Dim EmptyLines As Long

ProjectFile = Text1.Text
ProjectDir = sGetFileDir(ProjectFile)

Open ProjectFile For Input Lock Read As #1
Do Until EOF(1)
Line Input #1, Rad
Property = Left$(Rad, InStr(Rad, "=") - 1)

If (InStr(Rad, ";") > 0) Then
Value = Mid$(Rad, InStr(Rad, ";") + 2)
Value = Mid$(Rad, InStr(Rad, "=") + 1)
End If

Filename = ProjectDir & Value
Do While (InStr(Filename, "..") > 0)
Filename = sGetFileDir(Left$(Filename, InStr(Filename, "..") - 2)) & Mid$(Filename, InStr(Filename, "..") + 3)

Select Case Property
Case "UserControl", "Form", "Class", "Module"
Open Filename For Input Lock Read As #2
Line Input #2, Rad
Loop Until (Rad Like "Attribute VB_*")
Line Input #2, Rad
Loop Until Not (Rad Like "Attribute VB_*")
LineCount = LineCount + 1
Do Until EOF(2)
Line Input #2, Rad
LineCount = LineCount + 1
If (Len(Rad) = 0) Then EmptyLines = EmptyLines + 1
Close #2
End Select
Close #1

Me.Caption = LineCount & " (" & EmptyLines & " empty lines)"

End Sub

Function sGetFileDir(sPathIn As String) As String
' This procedure will retun just the path name from a
' string containing a path and file name.
Dim i As Integer
For i = Len(sPathIn) To 1 Step -1
If (Mid$(sPathIn, i, 1) = "\") Then Exit For
sGetFileDir = Left$(sPathIn, i)
End Function

Function sGetFileName(sFullPath As String) As String
Dim i As Integer
For i = Len(sFullPath) To 1 Step -1
If (Mid$(sFullPath, i, 1) = "\") Then Exit For
sGetFileName = Mid$(sFullPath, i + 1)
End Function

You will want to change the line
ProjectFile = Text1.Text
in the very first procedure to
ProjectFile = <the filename of your .vbp file with full path>

Then call the Command7_Click() sub and the number of lines will show in the caption of the form where you have the code.


Seems like a lot of work for a little task.  Use an add-in..  much easier and much more useful.

rcbarotAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.