Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Share an array between forms

Posted on 2001-06-20
8
Medium Priority
?
154 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 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
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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 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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

664 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