Click here to Skip to main content
Click here to Skip to main content

Visual FoxPro Lines of Code Analysis

By , 5 Jan 2012
 

Introduction

Being a long-time Visual FoxPro turned .NET developer, I am now faced with the task of porting several existing applications from VFP to .NET - and providing customers with estimates of effort for each project as well.

Since I could not find a Source Lines of Code (SLOC) tool for VFP projects, I decided to build one. This article is the result of my work and I hope someone else will find this tool useful in their work.

Using the Application

The VFPLOCCounter application is very easy to use - simply select the VFP *.pjx file you wish to analyze and then click the Process button.

The application will analyze code found in Forms (*.scx), Menus (*.mnx), Class Libraries (*.vcx), Programs (*.prg), Includes (*.h), and Reports (*.frx).

For each file, the application generates the following metrics:

  • Total number of lines of source
  • Number of methods
  • Number of lines of Code
  • Number of Comment lines
  • Number of Blank lines
  • Percentage of Code lines
  • Percentage of Comment lines
  • Percentage of Blank lines

Note the Percentage calculations are all based on the total lines in the file or project, for example, the Percentage of Code lines is calculated as follows:

fileCodePercent = (fileCodeLines / fileTotalLines) * 100;

After all files in the project have been analyzed, the application generates the above metrics for the project as a whole.

When the analysis is completed, you can produce a printable report by clicking the Print Preview button which is positioned to the right of the Process button.

Points of Interest

The report that the application generates is built using Microsoft Reporting and was for me an interesting excursion into this way of building reports.

Enjoy!

History

  • 29th May, 2007: Initial post
  • 31st August, 2011: Updated project to Visual Studio 2010, search "supexpr" field for code in report files
  • 30th December, 2011: Updated project, corrected bug that did not correctly account for lines containing a single character (such as a ? or a single tab). Also corrected bug that prevented Include files (.h) from being examined. Also correctly count comment lines that begin with "&&" as comment lines and not code lines. Starting a comment line with "&&" is considered bad form in VFP, but is allowed nonetheless.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Mark Miller
Software Developer (Senior)
United States United States
Member
I develop software for a leading healthcare system in Northern Illinois.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generalfoxpro project booksmembermicrocomputershisar2 Dec '08 - 20:22 
i want ebook on demo foxpro project. becuase i am a old dbase programer. i read book on visual foxpro 6. but i cann't upgrade my old projects to new.
 
please tell me the solution or send sombody a sample project so that i can run and get help.
 
ravinder
GeneralRe: foxpro project booksmemberMark Miller3 Dec '08 - 4:51 
If you are referring to converting dBase application to Visual FoxPro, you will likely run into a multitude of problems due to dBase being procedural in nature and VFP being OOP and event driven.
 
I would recommend reading several books on VFP that are available from Hentzenwerke[^].
 
I may be able to offer some help to you as well if needed.
 
Best of luck to you.
 
Sincerely,
 
-Mark
mamiller@rhsnet.org

QuestionDoes it work for Memo fields?memberAndrey Chekh30 Oct '07 - 10:51 
I cannot make it work for .vcx files - the file opened without errors but Methods fields values are always empty. I can read the values using Visual FoxPro or DBF Viewer though.
 
I've got the latest Visual FoxPro oledb provider version 9.0.00.3504
GeneralVery Well DonememberSteveC-A95 Jun '07 - 7:43 
That's it. This is a well-done piece of code that fills a much-needed niche for (VFP) developers.
 
Thanks.
GeneralRe: Very Well DonememberMark Miller5 Jun '07 - 9:24 
Steve,
 
Thanks!

 
Sincerely,
 
Mark D. Miller
mark@msdcweb.com
http://www.msdcweb.com

GeneralCorrectionsmemberAlexke4 Jun '07 - 22:24 
Hi Frank,
 
Thanks for your contribution. This tool is very much appreciated, but I had to do a few corrections to make it work (the results were not correct). There were some errors in your tests for comments.
In every Process... method I've changed the following line:
 
if (s.Substring(0, 1) == "*" || s.Substring(0, 3) == "*!*")
into:
if (s.Substring(0, 1) == "*" || (s.Length >= 3 && s.Substring(0, 3) == "*!*"))
 
I've also trimmed every 's' or 'vline'.
 
In the ProcessProgram method I've also made sure that '\t' was replaced with "".
 
br,
Alex
GeneralRe: CorrectionsmemberMark Miller5 Jun '07 - 4:41 
Alex,
 
Thanks, I see your point - if the line is only two chars long and not a comment, it could throw an exception.
 
Good catch!
 
I'll repost with these changes tonight.
 
Thanks.
 
Sincerely,
 
Mark D. Miller
mark@msdcweb.com
http://www.msdcweb.com

GeneralMigration Lines of Code Countermemberrajantawate1(http//www.jhatak.com)29 May '07 - 8:52 
hi,
 
i have developed a similar lines of counter for powerbuilder loc:
 

http://www.codeproject.com/useritems/Powerbuilder_LoC_Counter.asp[^]
 
do you work on migration projects.
 
Rajan Tawate
GeneralRe: Migration Lines of Code CountermemberMark Miller29 May '07 - 9:11 
I saw your article and thought that I should post my project as well.
Thank you for sharing and prompting me to do the same!
 
Yes, I do work on migration projects, mainly from VFP to .NET.

 
Sincerely,
 
Mark D. Miller
mark@msdcweb.com
http://www.msdcweb.com

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 5 Jan 2012
Article Copyright 2007 by Mark Miller
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid