There are some techniques that can help, but I don’t believe there is a DEFINITIVE way to automate removing unused variables. This topic has been discussed many times before, so I suggest a search on “delete unused variables” or similar phrase (without quotes of course) and review the previous discussions. You might find this topic useful.
Dwayne Hoffpauir (BOB member since 2002-09-19)