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 !
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

861 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