How to quickly identify unused variables?

Programming and macros
User avatar
loeb
Posts: 70
Joined: Sun Jan 16, 2022 5:55 pm
Answers: 1
x 39
x 10

How to quickly identify unused variables?

Unread post by loeb »

As I reuse code, I often end up with variables that are not used in my new routines. Identifying remnant variables is a tedious process which is compounded by SolidWork's tendency to frequently crash as I comment out variables I think are unused and then recompile. Do you have any tricks to clean up code like this?

Thank You
User avatar
gupta9665
Posts: 420
Joined: Thu Mar 11, 2021 10:20 am
Answers: 25
Location: India
x 438
x 459

Re: How to quickly identify unused variables?

Unread post by gupta9665 »

For vba macros, I comment out most of them (except the few which I can easily spot) and add Option Explicit at the top. Now when running the macro, SW will prompt for the undefined variables, and I remove comment from them. And keep on doing it until all done. There are some tools available, but I have never tried them.

When using VB.net, the system itself prompt for not required variables.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
Post Reply