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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
Add a module to your program and define it like this in the declarations section of the module:

   public names(2000) as integer


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Do I hear and echo?
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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. :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.