Click here to Skip to main content
13,799,009 members
Click here to Skip to main content
Add your own
alternative version


79 bookmarked
Posted 16 Jul 2005

ASP Code Analyzer

, 6 Dec 2006
Rate this:
Please Sign up or sign in to vote.
A simple tool to find unused subs, functions and variables in your ASP code.


The goal of this tool is to check an ASP project/folder for unused code elements. These elements include unused constants, global variables, functions, subs, and local variables. This comes in very handy if you undertake large changes in a project, or use include files from previous ASP projects and want to be sure, that you do not deploy unnecessary code.

This article will not describe in detail how the code works, since the main topic is how to get rid of unused elements, and the code is actually written in C#. It will, however, give you an understanding of how the tool operates and what its limitations are.

Using the analyzer

The ASP Code Analyzer is very easy to use. First download the executable, unzip it and run ASPCodeAnalyzer.exe. Next you can browse for the directory that contains your ASP project. Hit the 'Go' button and the analyzer will do its work. I would like to stress on the point that the analyzer will not change your files. It will merely point to the portions in your code where there are unused code elements.

If you have UltraEdit32 installed in your machine and if you double click on the findings list, the tool will automatically start UltraEdit32 and open the file on the corresponding code line. If you use a different editor, you can use the File/Options dialog to define your editor and the parameters used to open a specified file on a given line.

Your code has to be syntactically correct. Otherwise the analyzer will not work properly.

How the analyzer operates

Pass one

  • First the analyzer lists all the .asp and .inc files in the given directory and all its sub directories and puts them in a queue.
  • Now all the files in the queue are read. If the analyzer encounters include statements, it adds the referenced file to the queue if it's not already in it. If the included file does not exist on the hard disk, the analyzer writes a message to the error list at the bottom of the window.
  • While reading a file it strips all the HTML Code, all comments (including rem comments) and all texts that are surrounded by double quotes. The parser is smart enough to treat two consecutive double quotes as one single double quote.
  • Now that only the code is left of the original file, the analyzer creates an internal "code tree":
    • constants
    • global variables
    • global code
    • subs/functions
      • local variables
      • code
    • classes
      • methods
        • local variables
        • code

    The analyzer does not test whether classes are used in the code. Nor is it able to test whether specific members and methods of a class are used. It does however check, if local variables are used.

  • The local variables of subs, functions and methods are tested for usage while building the code tree. This is done by testing if the variable name is used in the code block.

Pass two

Now for the tricky part: Finding unused global variables and subs/functions.

  • First, all elements are considered unused.
  • Now all the files are processed again in groups. A group consists of a file plus all referenced files.
  • All elements of the current file group are examined. If the name of an element is used anywhere in the code of the file group, that element is considered used.

By examining file groups instead of files, an include file is tested in all possible contexts.

Matching the elements against the code

Let's say the analyzer wants to know if the sub WriteTd is used in a code block, then the following statements are matched:

call WriteTd( someVar)
call WriteTd ( someVar)

The following statements do not match, since the sub's name is actually just a part of the whole identifier:

call WriteTd2( someVar)
call MyWriteTd( someVar)


Be warned: Due to it's heuristic nature, the algorithm is probably not able to find all the unused elements in your code. On the positive side all its findings should really be unused elements.

The analyzer is unable to detected the following:

function test
  dim unusedVar
  unusedVar = 12
end function

Although the variable unusedVar is technically useless, since it is not used for processing anywhere, the analyzer will not notify you. Generally speaking, the analyzer will only point out those code blocks that you can delete without breaking the code.

Also, if you use local variables that shadow global variables the global variables are always considered used.

dim unusedGlobal

function test
  dim unusedGlobal ' Shadows the global variable
  unusedGlobal = 12
  Response.Write( unusedGlobal)
end function

Variables should not be defined in more than one line. In the following code:

dim a,b,c, _

the analyzer will only identify a, b and c as variables.


Despite its shortcomings the ASP Code Analyzer should give you a good impression on how clean your code actually is.


  • July 17th, 2005 - Initial release.
  • July 23rd, 2006 - Adjusted code to correct biggun's false positive.
  • December 6th, 2006 - Added handling of // comments.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Switzerland Switzerland
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionThanks fschudel for this wonderful tool Pin
pg_embedded8-May-13 19:46
memberpg_embedded8-May-13 19:46 
AnswerRe: Thanks fschudel for this wonderful tool Pin
fschudel8-May-13 23:06
memberfschudel8-May-13 23:06 
Generalgood tools Pin
Member 110714717-Jun-10 22:04
memberMember 110714717-Jun-10 22:04 
GeneralOption to only list local variables Pin
Edelcom24-Jan-10 23:06
memberEdelcom24-Jan-10 23:06 
GeneralRe: Option to only list local variables Pin
fschudel25-Jan-10 2:38
memberfschudel25-Jan-10 2:38 
GeneralRe: Option to only list local variables Pin
Edelcom25-Jan-10 3:40
memberEdelcom25-Jan-10 3:40 
GeneralEnforcing CodingStandards Pin
Vasudevan Deepak Kumar6-Dec-06 8:14
memberVasudevan Deepak Kumar6-Dec-06 8:14 
GeneralRe: Enforcing CodingStandards Pin
fschudel6-Dec-06 21:54
memberfschudel6-Dec-06 21:54 
GeneralRelated Tool Pin
Vasudevan Deepak Kumar6-Dec-06 8:13
memberVasudevan Deepak Kumar6-Dec-06 8:13 
GeneralError Pin
valamas_salmat5-Dec-06 19:26
membervalamas_salmat5-Dec-06 19:26 
GeneralRe: Error Pin
fschudel5-Dec-06 21:32
memberfschudel5-Dec-06 21:32 
GeneralVirtual Folders (IIS) vs FileSystem base approach Pin
toebens4-Dec-06 6:25
membertoebens4-Dec-06 6:25 
GeneralRe: Virtual Folders (IIS) vs FileSystem base approach Pin
fschudel4-Dec-06 9:17
memberfschudel4-Dec-06 9:17 
Generalthanks. Pin
Magallanes20068-Aug-06 12:22
memberMagallanes20068-Aug-06 12:22 
GeneralCheck unused CONST Pin
tkdmaster25-Jul-06 5:58
membertkdmaster25-Jul-06 5:58 
GeneralRe: Check unused CONST Pin
fschudel28-Jul-06 22:35
memberfschudel28-Jul-06 22:35 
QuestionFalse positive [modified] Pin
biggun13-Jul-06 15:15
memberbiggun13-Jul-06 15:15 
AnswerRe: False positive Pin
fschudel15-Jul-06 8:06
memberfschudel15-Jul-06 8:06 
GeneralRe: False positive Pin
biggun19-Jul-06 2:41
memberbiggun19-Jul-06 2:41 
GeneralRe: False positive Pin
Misael Monterroca17-Nov-16 6:37
memberMisael Monterroca17-Nov-16 6:37 
GeneralRe: False positive Pin
Member 109644356-Apr-17 15:21
memberMember 109644356-Apr-17 15:21 
GeneralThanks! Pin
wk63312-Jul-06 14:19
memberwk63312-Jul-06 14:19 
GeneralInteresting tool Pin
Don Miguel28-Jul-05 22:31
memberDon Miguel28-Jul-05 22:31 
GeneralRe: Interesting tool Pin
Havoxx3-Aug-05 6:55
memberHavoxx3-Aug-05 6:55 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.181207.3 | Last Updated 6 Dec 2006
Article Copyright 2005 by fschudel
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid