Solved

Share an array between forms

Posted on 2001-06-20
8
139 Views
Last Modified: 2010-05-02
Hello Experts. I think this is an easy one.

I tried to declare an array as public in my main form, as it must be accessed by various other forms. However, arrays cannot be public apparently.

What is the simplest way of making it available to other modules/forms?  

Thanks
0
Comment
Question by:DapperDan
8 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 150 total points
Comment Utility
insert a module into your project and declare the array there
0
 
LVL 4

Expert Comment

by:beckingh
Comment Utility
Add a module Globals.bas

and declare your array as Global there.
0
 
LVL 2

Expert Comment

by:chandukb
Comment Utility
Add New Module to your project, ex: modMain.bas

Declare the following:
Public garyParameterArray() as String

The above declaration is dynamic array, after declaring, you can use it anywhere in your project, just do the following:

    ReDim garyParameterArray(0 To 0)
    garyParameterArray(0) = "TEST"

So that u can redim anywhere u want with whatever size u want and use it.

Chandu
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
bobbit31 has the answer.
If you like to work on other way, you must reference the array with the name of the module/form that contains it:

form1.myarray
or whatever you named both.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 9

Expert Comment

by:Valliappan AN
Comment Utility
You could also, try declaring a string as public, in your module, or the main form. And use Split and Join functions of VB6, provided, your array is not that big.

Public gStrArray As String

In your passing form,

gStrArray = Join(yourArray,",")

In your getting form,

Dim localArray
localArray = Split(gStrArray,",")

Hope this helps,
Cheers.

0
 
LVL 9

Expert Comment

by:Valliappan AN
Comment Utility
If you declare it in your main form, then the public variable should be prefixed with the form name and a dot, like, mainform.gStrArray.
0
 

Author Comment

by:DapperDan
Comment Utility
Sorry for the delay in checking back. Thanks for all your comments. I will try this out when I get home from work tonight (UK time).

Cheers
0
 

Author Comment

by:DapperDan
Comment Utility
That was annoyingly simple. I have a lot to learn about VB :).

Seems fairest to give points to the first reply, but thanks to everyone.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now