VB6 code counter

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

[Webinar] Streamline your web hosting managementRegister Today

x
 
anthonycConnect With a Mentor Commented:
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

0
 
oumerCommented:
do you want to just count the number of lines in the code or make a line number at the front of each line?
0
 
corvanderlindenCommented:
VB6 has no code counter utility
I do not know of free one's, but there are several commercial tools like the Numega Tools
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
johnny6Commented:
rcbarot:

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)
Else
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)
Loop

Select Case Property
Case "UserControl", "Form", "Class", "Module"
Open Filename For Input Lock Read As #2
Do
Line Input #2, Rad
Loop Until (Rad Like "Attribute VB_*")
Do
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
Loop
Close #2
End Select
Loop
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
Next
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
Next
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.


John
0
 
anthonycCommented:
John,

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

Anthony
0
 
rcbarotAuthor Commented:
Thanks!
0
All Courses

From novice to tech pro — start learning today.