Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Declaring a public array

Status
Not open for further replies.

eargo

Programmer
Jan 3, 2003
12
GB
Hiya, how do you declare a public array? exactly? I can find no code snippets - and when I try:
public dim colorarray(1 To 15) As Long

I get an error. I've tried it inside a public function, and inside the calling cmd_button - and outside - still no joy. Basically, I want to be able to access the array from 1 Sub and 3 functions.

Thanks

Joseph.
 
try

public colorarray() As Long

it might work

Andrew299
 
try

public colorarray() As Long

it might work

When declaring a public array the berackets must be left empty
Andrew299
 
try

public colorarray() As Long

it might work

When declaring a public array the brackets must be left empty
Andrew299
 
When declaring a public array the brackets must be left empty

I don't think that's true. Are you sure?


Rob
[flowerface]
 


"By declaring a dynamic array, you can size the array while the code is running. Use a Static, Dim, Private, or Public statement to declare an array, leaving the parentheses empty, as shown in the following example.

Dim sngArray() As Single"

this is what it says in the help file about it I got no errors when I tried it. but perhaps I have misunderstood it
 
That bit of help just tells you how to declare a DYNAMIC array. If you don't need dynamic, then you just put the numbers in the parentheses.
Rob
[flowerface]
 
Joseph,

Variables declared Public must be placed in a standard code module, not in a code module for a worksheet, ThisWorkbook, etc. Variables in Subs and Functions can never be public, by definition. Declare your array in a standard code module as follows:

Code:
Public ColorArray(1 To 15) As Long


Andrew - No problem; one of the great things about this forum is the natural checks & balances provided by members having varied backgrounds and experience.


Regards,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top