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   
QuestionIt's not working for all filesmemberMember 818891631 Aug '11 - 6:32 
Hi,
 
This is good toll, but doesn't work for all files.
 
For ex I have 32 .FRX files but it is counting for only 17 files. Same thing for prg files and reports.
AnswerRe: It's not working for all files PinmemberMark Miller31 Aug '11 - 7:03 
I cannot explain why it is not analyzing all the files available. I have never seen that happen, but then again I haven't used this in over 4 years.
 
I'll have to pull the application into my machine and look at it which I can do this evening.
Sincerely,
 
-Mark
mamiller@rhsnet.org

GeneralRe: It's not working for all files PinmemberMember 818891631 Aug '11 - 10:17 
Thanks for quick response..!
GeneralRe: It's not working for all files PinmemberMember 818889431 Aug '11 - 10:30 
I have also noticed that, for Reports, the LOC reported is too low.
 
If LOC is low, not enough time will be allocated by my manager, because they go by the LOC.
 
Thanks
Johnson
GeneralRe: It's not working for all files PinmemberMark Miller31 Aug '11 - 17:56 
After looking over the program it occured to me that the problem may be that some of the reports, programs, forms, etc that are part of the VFP application may not be included in the application project file. This tool will only analyze those files that are found in the PJX file. If it isn't in the PJX, it won't be analyzed.
 
As for the reports LOC count being low, I discovered on VFP 9 reports there are two fields that can contain code - 'expr' and 'supexpr' and the tool was not examining the 'supexpr' field. That has been added to the code.
 
I have submitted an update to the article with updated source code. If you need the source code prior to the CP editors updating the article, give me an email address and I'll send it to you.
Sincerely,
 
-Mark
mamiller@rhsnet.org

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