Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reference a variable declared in VBA James Excel Worksheet Functions 3 September 12th 08 10:31 PM
Challenging question: add TIME TREND in Excel with built-in functi Patrick Excel Discussion (Misc queries) 0 August 20th 08 02:13 PM
Array declared with the Static keyword clears itself between calls [email protected] Excel Programming 5 August 11th 08 04:07 PM
How to reference a public array (declared in module) from a proced Amzee Excel Programming 3 January 11th 05 06:26 PM
Can Not Find declared dll Ian Parker[_2_] Excel Programming 0 February 5th 04 10:50 PM


All times are GMT +1. The time now is 07:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"