I've been searching around for a way to clear all variables, and I've found some mentions of it, but the question is usually asked in efforts to fix another problem and a different/limited solution ends up being sufficient for the user.
What I have learned is that variables declared at the module level, opposed to the procedure level, do in fact retain their values after nominal code completion, and I also know you can clear individual variables by setting them to nothing. What I don't know is how to clear all variables at once, regardless of how many there are and what they are named.
As a workaround, I was thinking that I could just use a for each loop to do it one at a time, but I can't find that there is a collection object for variables... ?
What I have learned is that variables declared at the module level, opposed to the procedure level, do in fact retain their values after nominal code completion
The best thing to do is try and keep the declarations inside an object other than a module, or within declarations..
Global, Public And Variables Dim'd in the declaration section of a module become available throughout the project.
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
typically i would declare them at the procedure level, but in this case i have several subs within the module that need to share various variables, and i was trying to get around having to pass them explicitly within the procedure calls.
is there a way to declare module level variables at the procedure level? might result in the same problem i guess...
you can declare module specific variables by declaring them as Private, therefore they will not be available outside of the module..
If the module is used for a set of functions look into creating it as Class module, therefore all variables within this will be cleared when you terminate the class..
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
you can declare module specific variables by declaring them as Private, therefore they will not be available outside of the module..
it's my understanding that this is true when you make a private declaration at the module level only, which is actually the same as using a dim statement at the module level. if you use a public declaration at the module level, then the variable is available outside the project as well as throughout the module. as far as i know you can't use public or private declarations at the procedure level.
to clarify, i want to declare variables such that they will be shared across multiple procedures within a single module, and i want some way to clear their values at the beginning and/or end of code execution.
i've never used class modules, and i'm not familiar with how they work and how they compare to standard modules... guess i'll have to check them out.
that works for one variable at a time, but not for all.
i'm trying to avoid creating multiple places where i have to maintain a complete list of all my variables. call it lazy if you want... i prefer "effort efficient."
for example, i'd like a single function (i.e., application.reset, .clearmemory, .clearallvariables, etc.), or if someone smarter than me knows how i could repeat a method for clearing a single variable (i.e., dim var, var = empty, etc.) using a for loop or something in a way that would be independent of how many variables have been declared, that would suffice. something like
for each var in variablescollection
var = empty
next
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...