View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Need help creating, manipulating and reading global arrays ...

Public myArray(0 To 10) As String

Sub Test()
myArray(0) = "Test"
MsgBox (myArray(0))
End Sub

worked fine for me in a general module. (at least the Public statement must
be in a general module [Insert=Modlue] in the same workbook.

--
Regards,
Tom Ogilvy


" wrote:

I have been trawling for days for what must be VERY simple ... I just
cant find it :(

I would like to create a global array, populate it from one function,
wait for user interaction, then read from it in another. Sound simple?
Well ...

I have tried the following (the most simple example I could think of):

Public myArray(0 To 10) As String

Sub Test()
myArray(0) = "Test"
MsgBox (myArray(0))
End Sub

When trying to run 'Test', I receive the error "Sub or Function not
defined" on the "myArray(0) = "Test"" line ...

Regardless of setting 'myArray' as public, 'Test' is not recognizing
the global array ... it thinks it is a function ...

The below works, but of course in this example 'myArray'is not global,
which is what I need:

Sub Test()
Dim myArray(0 To 10) As String
myArray(0) = "Test"
MsgBox (myArray(0))
End Sub

What must I do to actually create and then use a global array? I need
help quick! running out of hair!

Cheers!