Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need help creating, manipulating and reading global arrays ...

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   Report Post  
Posted to microsoft.public.excel.programming
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!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Need help creating, manipulating and reading global arrays ...


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
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
Manipulating Arrays Alan Beban[_2_] Excel Worksheet Functions 0 November 8th 07 08:10 PM
Functions for manipulating arrays Alan Beban[_2_] Excel Discussion (Misc queries) 0 September 24th 07 07:05 AM
Functions for manipulating arrays Alan Beban[_2_] Excel Worksheet Functions 0 September 24th 07 07:04 AM
A hard one for manipulating arrays Jon Peltier Excel Programming 4 January 4th 07 11:42 AM
A hard one for manipulating arrays Alan Beban Excel Programming 0 January 3rd 07 10:18 PM


All times are GMT +1. The time now is 12:34 PM.

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

About Us

"It's about Microsoft Excel"