Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global 2-D Array...Is it possible?

Status
Not open for further replies.

daughtery

Programmer
Dec 12, 2006
66
US
I need to load a 2-D array in one form and access it from another form but I get an error when compiling stating something about it being illeagle to set global array in the declarations section. Got the same thing when I tried to declare it in the global.bas file. Is there any way around this? I already have some procedures complete based on this architecture and would hate to rewrite everything.
 
Its quite legal to do this
Code:
Public myArray(10, 10)               As String
in the General Declarations section of a module and have it visible throughout the application. You cannot however write any code in general declarations that sets values or manipulates the array.
Code:
Public myArray(10, 10)               As String
myArray(1, 1) = "Joe"  [red]<-- Illegal in General Declarations[/red]
 
I've done it. Put it in your Sub Main in the General Declariations.

Public aryMine() As String


I tried to have patience but it took to long! :) -DW
 
How about as integer? The declaration I had was

Public myArray (3,1) As Integer

It gave me an error
 
I just put Public myarray(3, 1) As Integer (Sub Main)
in my curernt app and compiled it to an EXE and got no errors?

I tried to have patience but it took to long! :) -DW
 
If you try and declare the array as PUBLIC in the General Declarations area of a form (as opposed to a module) it will throw you an error. If you DIM them in the General Declarations section it won't throw you the error. As everyone else has stated declaring them as Public in a module or in Sub Main will allow you to use the array.

Cheers

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
I forgot to mention that obviously if you DIM the array you won't be able to use it in the other form, it was just an example to show that you could use an array in the General Declarations of a form.

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 

Actually you can use it in another form if it is passed\retireved to\from a proceedure or Property Get\Let.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top