Share via


Is there a way to discover all unused variables in Visual Studio (VB.NET)?

Question

Thursday, March 31, 2016 11:24 AM | 2 votes

Hi, everybody

I use Visual Studio (VB.NET) to develop add-ons.

Very often, I declare a number of variables (with Dim) which I finally don't use in my application.

I naturally wish to identify and delete these unused variables.

When I build my add-on in Visual Studio, it does not give any error message.

Does Visual Studio provide a way to identify all unused variables? How?

Thanks

Leon Lai Kan

====

PS:

In Project Properties -> Compile Tab, I marked "Unused Local Variable" as Warning, and also as Error, but during Build, no error message is displayed by Visual Studio. Am I doing it wrong?

All replies (5)

Friday, April 1, 2016 5:20 AM ✅Answered | 1 vote

Hi Leon,

I am afraid Visual Studio(VB.NET) doesn't have this option "Code Anlayze" in project property.

I suggeset you'd better use VS2015 Community instead of using Visuao Studio(VB), then you will find "Code Analyze" in project property.

Then build your project, it will achieve your requirement.

Best Regards,

Lake Xiao


Friday, April 1, 2016 7:17 AM ✅Answered

Hi Leon,

>>So, with VS2010 there is no way I can make the software highlight all unused dims?

Yes, if your VS2010 doesn't have this option.  I am afraid there is no any other way to highlight all unused variables.

Best Regards,

Lake Xiao


Thursday, March 31, 2016 1:03 PM | 2 votes

If you see Analyze tab in Project Properties window, then specify “Enable Code Analysis on Build” and select “Microsoft All Rules”. Then rebuild the solution.


Thursday, March 31, 2016 2:00 PM

Hi Viorel

Thanks a lot for your reply.

I program regularly with VB.NET using Visual Studio. But I am an amateur and never paid much attention to the VS interface itself.

I don't find the Analyse tab. Pl see picture below.

Could you help me find it?

Best Regards,

Leon Lai Kan


Friday, April 1, 2016 6:09 AM

Hi Lake Xiao

Thanks a lot for your reply.

I use Visual Studio 2010 Professional.

So, with VS2010 there is no way I can make the software highlight all unused dims?

Best Regards,

Leon