Solved

Share an array between forms

Posted on 2001-06-20
8
148 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 150 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Independent Software Vendors: 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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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
Course of the Month4 days, 15 hours left to enroll

635 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