Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Question about globally declared array not available in functi
I've run into problems multiple userforms send data between the forms. the
invisible text boxes solved the problems I was having. "Jim Thomlinson" wrote: Why not just read from the globally defined array? -- HTH... Jim Thomlinson "Joel" wrote: A trick in passing variable into a userform is to make a textbox on the userform for passing arguments (as text strings) and make the textbox invisible. Nobody can see the textbox but the macro can read and write to an invisible textbox. When putting in arguements use Join() function and seperate the arguments using commas. Then insie the userform use Split to seperate the CSV parameters. "Jim Thomlinson" wrote: Based on your description there is nothing wrong with your code... here is some code that I created as a test and it works In a blank module add Public MyArray(0 To 3) As String Sub Populate() MyArray(0) = "A" MyArray(1) = "B" MyArray(2) = "C" MyArray(3) = "D" End Sub In a blank user form add... Private Sub UserForm_Click() Call Populate MsgBox MyArray(0) End Sub Run the code in the userform and click on the form. The message box appears showing A A couple of possibilities... Are you using option explicit in your code? If not then you might have declared MyArray (spelled incorrectly) on the fly. If you have used the stand alone line of code End That clears all global variables when executed. -- HTH... Jim Thomlinson "ker_01" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Reference a variable declared in VBA | Excel Worksheet Functions | |||
Challenging question: add TIME TREND in Excel with built-in functi | Excel Discussion (Misc queries) | |||
Array declared with the Static keyword clears itself between calls | Excel Programming | |||
How to reference a public array (declared in module) from a proced | Excel Programming | |||
Can Not Find declared dll | Excel Programming |