Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default arrays - module to module

Is it possible to create an array in one module and then
write the array in another module OR does all the activity
have to tale place in one module? Thanks for the help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default arrays - module to module

It's possible if you declare the variable as Public in a regular code
module outside a procedure. See "Understanding Scope and Visibility" in
VBA Help.



In article ,
"mike" wrote:

Is it possible to create an array in one module and then
write the array in another module OR does all the activity
have to tale place in one module? Thanks for the help

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default arrays - module to module

Mike,

What you want is perfectly feasible. You could either declare the array as a
module variable, that is at the start of the module and not in a macro, or
you could pass it ByRef as an argument from one procedure to another, which
passes the variable pointer and allows updating in another procedure.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"mike" wrote in message
...
Is it possible to create an array in one module and then
write the array in another module OR does all the activity
have to tale place in one module? Thanks for the help



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default arrays - module to module

Hi!

Either you can declare the array as a public variable on the General section of one of the modules and then simply reference the array in both modules since it is a global variable, or you can send it from Sub (or Function) to Sub (or Function) as a parameter. A variant can contain an array so you can allso send the array in a variant parameter but if you know the typw of data you just declare an array without telling the size in the parameter declaration.

Example:

Sub test()
Dim lngArray(10) As Long

PopulateArray lngArray()
PrintArray lngArray()
End Sub

Public Sub PopulateArray(ByRef lngArray() As Long)
Dim lngLowerBound As Long
Dim lngUpperBound As Long
Dim lngCounter As Long

lngLowerBound = LBound(lngArray)
lngUpperBound = UBound(lngArray)

For lngCounter = lngLowerBound To lngUpperBound
lngArray(lngCounter) = lngCounter
Next
End Sub

Public Sub PrintArray(ByRef lngArray() As Long)
Dim lngLowerBound As Long
Dim lngUpperBound As Long
Dim lngCounter As Long

lngLowerBound = LBound(lngArray)
lngUpperBound = UBound(lngArray)

For lngCounter = lngLowerBound To lngUpperBound
Debug.Print lngArray(lngCounter)
Next
End Sub

In this example the three different Subs can be placed in three different modules and still work together.

Good luck!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CLASS MODULE & SIMPLE MODULE FARAZ QURESHI Excel Discussion (Misc queries) 1 September 7th 07 09:32 AM
Importing Alan Beban's code on Arrays; Importing a module or a project Steve G Excel Worksheet Functions 4 August 27th 07 04:18 PM
code in module A to not execute a Worksheet_SelectionChange sub of another module Jack Sons Excel Discussion (Misc queries) 4 December 11th 05 11:52 PM
Module Monty Excel Discussion (Misc queries) 4 May 19th 05 08:34 AM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


All times are GMT +1. The time now is 02:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"