How to write an Add-in to find the useless variables

Posted on 2000-04-28
Last Modified: 2010-05-02

How to write an Add-in or anything to find
1. the declared variables never be used in the program,
2. the variables assigned value but never be used,
3. anything similar you think we should do.
Question by:username1

Expert Comment

ID: 2759221
Thats a biggie - I suspect you might need to offer more than 70 pts.

Keep your eyes peeled on - I'm just completing a tool to do that among other things - I'll post the source when finished !

Expert Comment

ID: 2759343
Here is the site I posted for you yesterday on your other question.  I think that this will be the simplest way:    hope this helps.

Expert Comment

ID: 2759658
Creating an add-in is the straightforward bit. Determining what has or hasnt been used is a different kettle of fish entirely !
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.


Accepted Solution

Sage020999 earned 70 total points
ID: 2759713
After you fiqure out how to write an add-in, you will need to use the active code panes to search for any Dimmed varibles.  You will need some sort of function that determines if the varible is a field name, varible name, comment, or a function call.  The comments are the easiest to solve.  Any lines beginning with the single quote ', you would ignore. Any Varibles following the DIM statement you would want to stick in an array.  It is important to remember scoping here.  You will have the potential of having a Public varible named the same as private varibles.  Once you have your array, you will want to search for the whole word that matches the varible name.  This will exclude field names which are either formatted ('Field'),!Field, or [Field].  Everything else is a varilbe being used.  You then want to have a counter to count the times the varible is found within the scope.  Once you find it once, you can move to the next varible.  This is not an easy task and will take some time.  These are one of those tasks that cost more to do than purchase, but would be rewarding after the completion of the project.  Good Luck. I hope this helps a little.  -Sage.  This is an interesting topic, I hope you receive some feed back from people who have done simular tasks.  I have created multiple clip boards, modified text, but as far as searching for unused varibles, I purchased VBCompress Pro.
LVL 38

Expert Comment

ID: 2759975
Could be done as an add-in or as a stand alone project.  As a stand alone, you would use the project file to find out which files to parse and then do what Sage says above.  

Also, you might want to consider creating a call tree of routines to find dead code.  Variables used in dead code are not really used.

Basically, you would need to trace any routine (Sub, Function or Properties) called from startup modules and/or user-interface and follow any routines called from those etc.

Then any routines that are left over could be flagged as dead and displayed in a list to the user.

This is a big project, good luck!


Expert Comment

ID: 2761008
You'll also need to keep track of functions with the same name as variables, variables declared with type identifiers (!, %, $, #), multiple variables dimensioned on single lines etc,etc etc

I have an application developed in-house and if I can persuade the author to let me publish I'll do so, but its too large to publish here. I'll try and post it on a web site somewhere  (as I understand its against house-rules to e-mail answers to individuals).

Author Comment

ID: 2764150

Thank you for all experts who gave me usefull suggestions.

This is not as easy as I thought....if VB7 or VB2000 wont do this and I have spare time, I will try :-)


Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question