[RESOLVED] How to find unused variables in project
HI all,
In my project there are lot of variables, and some of them are not used at all.I want to clean up the code by removing these unused variables. These variables are not shown as unused when i build the application. The problem is with the global variables, and not with the local varible for a function .Is there a method to find these unused variables?
Re: How to find unused variables in project
Is there a tool which can be used to optimize the code and also to find which all part of code is dead code( like some invalid if condtion which may never happen )
Re: How to find unused variables in project
When you build the solution, you should see warning messages that tell you which variables are unused. You can use those warning messages to identify the un-used stuff and remove it.
Re: How to find unused variables in project
Is there a thing called a Global Variable in VB.NET. I thought that all the variables and functions, belonged to a class and hence called members/methods respectively. Please tell me if I am wrong?
BTW, as suggested by Shuja, VS debugger is your best tool.
Quote:
Is there a tool which can be used to optimize the code and also to find which all part of code is dead code( like some invalid if condtion which may never happen )
I am sure there might be one, but that just might sugar coat what the VS debugger does....
For your post #1, better read this if have any ambiguity...
Hope that helps a bit
Bhushan.
Re: How to find unused variables in project
PUBLIC variables are variables declared Globally.
Re: How to find unused variables in project
Quote:
Originally Posted by
dglienna
PUBLIC variables are variables declared Globally.
I want to know which all public variables are unused.
Also, if the variables are decalred in the class, then if it is not used, the warnings wont come up. If it is in the functions, then the warning will come up.
Re: How to find unused variables in project
Well, since vb.Net shows you the errors when you enter a line of code, you could easily comment out all the variables (I keep all my variables at the top of the class, so I just highlight all the variables and hit the comment button), and you will get a list of errors for each variable. As you un-comment the variables, the errors will disappear. When you are down to no errors, then you can delete the still commented out variables.
Re: How to find unused variables in project
Quote:
Originally Posted by
bhushan1980
Is there a thing called a Global Variable in VB.NET. I thought that all the variables and functions, belonged to a class and hence called members/methods respectively. Please tell me if I am wrong?
Yes there is such a thing. A variable declared as public in module is a global variable as are subs and functions which are declared as public in a module.
If on the other hand they are declared in a form or other class they are not global but are a member of the class object.
Re: How to find unused variables in project
I have found a tool which tells about unused variables in project.
check www.aivosto.com
Code:
Project Analyzer
Source code analyzer for Visual Basic, VB.NET and VBA
I found this tool useful.
Regards/-
Makdu