unwanted reinitialization of global variables
Dave,
I think I figured it out. I looked at a section of the Visual Basic
help called "Understanding the Lifetime of Variables". Here is an
excerpt:
When a variable loses scope, it no longer has a value [....] If a
procedure-level variable is declared with the Static keyword, the
variable retains its value as long as code is running in any module.
When all code has finished running, the variable loses its scope and
its value. Its lifetime is the same as a module-level variable. A
module-level variable differs from a static variable. In a standard
module or a class module, it retains its value until you stop running
your code.
The code stops running between the first click of the Routine2 command
button and the second click of the button. I guess because the code
is no longer running, the variable loses scope and therefore gets
reinitialized to a null value. So, I guess this is the way it is
designed to work, and there is no way to avoid the variables being
reinitialized. I will use the initializevars subroutine that you
suggested.
Thanks!
- Mary
|