Solved

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

Posted on 2000-04-28
7
176 Views
Last Modified: 2010-05-02
Hi,

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.
0
Comment
Question by:username1
7 Comments
 

Expert Comment

by:morpho
Comment Utility
Thats a biggie - I suspect you might need to offer more than 70 pts.

Keep your eyes peeled on www.morpho.co.uk - I'm just completing a tool to do that among other things - I'll post the source when finished !
0
 
LVL 2

Expert Comment

by:Sage020999
Comment Utility
Here is the site I posted for you yesterday on your other question.  I think that this will be the simplest way:  http://vb-world.net/articles/addins/    hope this helps.
0
 

Expert Comment

by:morpho
Comment Utility
Creating an add-in is the straightforward bit. Determining what has or hasnt been used is a different kettle of fish entirely !
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 2

Accepted Solution

by:
Sage020999 earned 70 total points
Comment Utility
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.
0
 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
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!

0
 
LVL 3

Expert Comment

by:paulstamp
Comment Utility
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).
0
 

Author Comment

by:username1
Comment Utility
Hi,

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 :-)

Cheers.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now