View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Shawn Shawn is offline
external usenet poster
 
Posts: 271
Default 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