Thursday, October 09, 2008

Visual Basic 6 Support for Microsoft's LOC Counter

Microsoft has released a great free lines-of-code (LOC) counter.  It is available for download here:

The tool, however, doesn't come with VB6 support.  As much as I hate VB6, we still have a ton of it where I work.  Luckily, the tool is extensible and by editing the LineCounters.xml file and creating some regular expressions I was able to get it to work pretty well with VB6.  The LineCounters.xml file is installed in the same directory as the program.  Open it in your favorite text editor and plop in the following lineCounter section (after one of the /lineCounter closing tags of course):

<lineCounter name="VB6">





  <codeArea name="Blank lines" isCode="false">



  <codeArea name="' comments" isCode="false">



  <codeArea name="VB6 Class and Form Garbage" isCode="false" multiLine="true">


      <endExpression>^Option Explicit.*$</endExpression>


  <codeArea name="VB6 File Attributes" isCode="false">



  <codeArea name="VB6 Option Explicits" isCode="false">

      <expression>^Option Explicit.*$</expression>


  <pspMetricArea name="Class" toCount="true" caseSensitive="false" >






  <pspMetricArea name="Method" toCount="true" caseSensitive="false" >







Note that for this to work properly to remove the garbage at the top of a form file the forms must have "Option Explicit" in them.  This worked for me as that has always been a standard.  Hopefully it is useful for someone else.

1 comment:

David said...

Exactly what I needed. Funny, this post is 8 years old and perfectly matched what I needed for some VB6 apps we are converting. Thanks!