Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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! |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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! |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() It works for me. I get a message box with "Test". The public declaration should be in a standard module, not the ThisWorkbook module or a module attached to a sheet. Also, the ( ) around myArray(0) is not required. -- Jim Cone San Francisco, USA http://www.realezsites.com/bus/primitivesoftware wrote in message 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! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Manipulating Arrays | Excel Worksheet Functions | |||
Functions for manipulating arrays | Excel Discussion (Misc queries) | |||
Functions for manipulating arrays | Excel Worksheet Functions | |||
A hard one for manipulating arrays | Excel Programming | |||
A hard one for manipulating arrays | Excel Programming |