ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   duplicate declaration (https://www.excelbanter.com/excel-programming/324266-duplicate-declaration.html)

[email protected]

duplicate declaration
 
I am trying to pass an array as an argument to a user defined function,
and would like to also then pass the same array to other routines in
the same module, however not as arguments but using module level
declarations like Private.

Although I do not receive the "duplicate declaration" statement the
arrays are zeroed out once the current function is left for a
subroutine call.

is there any convenient way to transfer this array without using it
repeatedly as an argument? I have a chain of subroutine calls
(subroutines which call other subroutines) all of which refer to the
same array, and the easiest is to make the array accessible anywhere in
the module.

The original program (Fortran) read the array in from an input file and
transfered the contents using common blocks.

appreciate any assistance.

dan


Shawn

duplicate declaration
 
" wrote:
Although I do not receive the "duplicate declaration" statement the
arrays are zeroed out once the current function is left for a
subroutine call.


So you're declaring the variable in each function? In VBA, that means that
each of your arrays goes out of scope when the function completes.

It sounds like you want to declare the array at module level, at the
beginning of the module, outside of any function definitions, just after the
initial "Option Explicit" line. (Which you should always have turned on in
your VB editor options to save you from typos and thinkos associated with
variable names.)

At the top of your module:

Option Explicit
Dim MyArray() as Integer ' if you want a resizable (dynamic) array
Dim FixedArray(5) as Integer ' if you don't

But think about passing the array as an argument. That will make it easier
to use your function in another module someday without messing around with
module level variables and name conflicts and who knows what other
frustrations.

--Shawn


All times are GMT +1. The time now is 03:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com