K
ker_01
I have one module and one userform (I'm asking this as a general question
first, to save the group from having to wade through some ugly code).
I declare a Global array at the top of the module
Global MyArray(0 to 3)
In my sub, I assign values
MyArray(0) = "A"
Then when a cmdbutton on the userform is clicked, some other code is run,
which then triggers a private function behind the userform. One of those
lines needs my variable, so I try to use it, and it is empty.
I set up a watch, and
Expression Value Type Context
MyArray(1) "A" String MyModule.MySubName
MyArray(1) <out of context> variant/empty MyUserForm.MyPrivateFunction
I do not declare the array anywhere other than the top of the module, and I
don't erase the array anywhere.
Why does Excel think these are two different arrays or variables (with two
different simultaneous values) instead of treating them as the same array,
accessed in two different places? What is the appropriate way to create a
truly accessible array in my sub so that the userform's private function can
access the values?
I don't want to pass the values directly, because the private function is
called from 10 different places, and I these values will be static after they
are assigned in the sub (they are assigned from worksheet values, so I can't
hardcode it)
Any advice is greatly appreciated!!
Thank you,
Keith
first, to save the group from having to wade through some ugly code).
I declare a Global array at the top of the module
Global MyArray(0 to 3)
In my sub, I assign values
MyArray(0) = "A"
Then when a cmdbutton on the userform is clicked, some other code is run,
which then triggers a private function behind the userform. One of those
lines needs my variable, so I try to use it, and it is empty.
I set up a watch, and
Expression Value Type Context
MyArray(1) "A" String MyModule.MySubName
MyArray(1) <out of context> variant/empty MyUserForm.MyPrivateFunction
I do not declare the array anywhere other than the top of the module, and I
don't erase the array anywhere.
Why does Excel think these are two different arrays or variables (with two
different simultaneous values) instead of treating them as the same array,
accessed in two different places? What is the appropriate way to create a
truly accessible array in my sub so that the userform's private function can
access the values?
I don't want to pass the values directly, because the private function is
called from 10 different places, and I these values will be static after they
are assigned in the sub (they are assigned from worksheet values, so I can't
hardcode it)
Any advice is greatly appreciated!!
Thank you,
Keith