Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Share an array between forms

Posted on 2001-06-20
8
Medium Priority
?
157 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 600 total points
ID: 6211829
insert a module into your project and declare the array there
0
 
LVL 4

Expert Comment

by:beckingh
ID: 6211842
Add a module Globals.bas

and declare your array as Global there.
0
 
LVL 2

Expert Comment

by:chandukb
ID: 6211873
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6212317
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
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6213017
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
ID: 6213019
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
ID: 6214850
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
ID: 6215640
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

916 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