CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2009
    Location
    Kuwait
    Posts
    170

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

  2. #2
    Join Date
    Jul 2009
    Location
    Kuwait
    Posts
    170

    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 )

  3. #3
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    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.

  4. #4
    Join Date
    Jun 2006
    Posts
    645

    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.
    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How to find unused variables in project

    PUBLIC variables are variables declared Globally.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Jul 2009
    Location
    Kuwait
    Posts
    170

    Re: How to find unused variables in project

    Quote Originally Posted by dglienna View Post
    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.

  7. #7
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    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.

  8. #8
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: How to find unused variables in project

    Quote Originally Posted by bhushan1980 View Post
    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.

  9. #9
    Join Date
    Jul 2009
    Location
    Kuwait
    Posts
    170

    Resolved 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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured