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

    Question

  • 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?

    • Edited by Leon Lai Thursday, March 31, 2016 11:36 AM
    Thursday, March 31, 2016 11:24 AM

Answers

  • 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

    • Proposed as answer by lake XiaoModerator Friday, April 1, 2016 7:17 AM
    • Marked as answer by Leon Lai Friday, April 1, 2016 10:13 AM
    Friday, April 1, 2016 5:20 AM
    Moderator
  • 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

    • Marked as answer by Leon Lai Friday, April 1, 2016 10:13 AM
    Friday, April 1, 2016 7:17 AM
    Moderator

All replies

  • 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 1:03 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

    Thursday, March 31, 2016 2:00 PM
  • 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

    • Proposed as answer by lake XiaoModerator Friday, April 1, 2016 7:17 AM
    • Marked as answer by Leon Lai Friday, April 1, 2016 10:13 AM
    Friday, April 1, 2016 5:20 AM
    Moderator
  • 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

    Friday, April 1, 2016 6:09 AM
  • 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

    • Marked as answer by Leon Lai Friday, April 1, 2016 10:13 AM
    Friday, April 1, 2016 7:17 AM
    Moderator