Public array problems....

i have an array in a form called
>dim names(2000) as integer

however i want to be able to access the data in this array from other forms. I tried setting it as a "public" ie >public names(2000) as integer

but i am told this cannot be done! - there must be a way round this - and a fairly obvious one i am sure!

thanks foir any help you can provide
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

mcriderConnect With a Mentor Commented:
Add a module to your program and define it like this in the declarations section of the module:

   public names(2000) as integer

You can place your array in the general declarations portion of a bas module and declare it as public.  This will allow easy access from anywhere in your program.

Also, if you have a dynamic number of elements that will be contained in the array, take a look at 'redim preserve' in the help files.
Do I hear and echo?
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

No, that wasn't an echo, it was unison! Check the posing times:

   From: jjmartin
 Date: Tuesday, February 01 2000 - 04:21PM EST
   From: mcrider
 Date: Tuesday, February 01 2000 - 04:21PM EST

Put this in the form declaration part..

   Private m_Names(2000) as integer

Then you can add two public properties to access the array, like this..

   Public Property Let Names(Index as Integer, New_Value As Integer)

      m_Names(Index) = New_Value

   End Property

   Public Property Get Names(Index as Integer) As Integer

      Names = m_Names(Index)

   End Property

Using this kind of code you can access the array with code like..

   'Show the first item
   Me.Caption = formname.Names(1)

   'Change the first item to 10
   formname.Names(1) = 10
Your right mc, my bad. :)
All Courses

From novice to tech pro — start learning today.