declaring public array var issue

D

djc

I am declaring a dynamic array variable using Public keyword in the
declarations sections of a form. I need it to be available to another form
that is called from this form.

Public TestArray() As String

I get this error when trying to doing anything... at any event on the form:

"The expression on 'insert any event here' you entered as the event property
setting produced the following error: Constants, fixed length strings,
arrays, user defined types, and declare statements not allowed as public
members of object modules." It goes on further to say:

"The expression may not result in the name of a macro , the name of a
user-defined function, or [event procedure]. There may have been an error
evaluating the function, event, or macro"

Whats this about? What did I do wrong? Can't I make a public array variable?
 
L

losmac

You can't declare public variable in the declarations
sections of a form.
Insert new module in module window and declare this
variable there.
 
D

djc

thanks

losmac said:
You can't declare public variable in the declarations
sections of a form.
Insert new module in module window and declare this
variable there.

-----Original Message-----
I am declaring a dynamic array variable using Public keyword in the
declarations sections of a form. I need it to be available to another form
that is called from this form.

Public TestArray() As String

I get this error when trying to doing anything... at any event on the form:

"The expression on 'insert any event here' you entered as the event property
setting produced the following error: Constants, fixed length strings,
arrays, user defined types, and declare statements not allowed as public
members of object modules." It goes on further to say:

"The expression may not result in the name of a macro , the name of a
user-defined function, or [event procedure]. There may have been an error
evaluating the function, event, or macro"

Whats this about? What did I do wrong? Can't I make a public array variable?


.
 
A

Albert D. Kallal

You can do that, but you can certainly create a custom property for the form
that does exactly the same thing.

So,

Dim sA(10) As String

Public Property Let PArray(i As Integer, s As String)


sA(i) = s


End Property

Public Property Get PArray(i As Integer) As String

PArray = sA(i)

End Property


Now, you can just use/set values in the array like:

frm.PArray(4) = "Hello"

msgbox frm.PArray(4)

Of couse, "frm" is a valid form ref, so you might have:

forms("your form").Parray(4) = "Hello"

or

forms![Your Form"].PArray

Etc.

Essentially, you get to use the array, and it is public by use of a public
custom form property.
 
D

djc

very interesting approach. I'll play with that. Thanks!

Albert D. Kallal said:
You can do that, but you can certainly create a custom property for the form
that does exactly the same thing.

So,

Dim sA(10) As String

Public Property Let PArray(i As Integer, s As String)


sA(i) = s


End Property

Public Property Get PArray(i As Integer) As String

PArray = sA(i)

End Property


Now, you can just use/set values in the array like:

frm.PArray(4) = "Hello"

msgbox frm.PArray(4)

Of couse, "frm" is a valid form ref, so you might have:

forms("your form").Parray(4) = "Hello"

or

forms![Your Form"].PArray

Etc.

Essentially, you get to use the array, and it is public by use of a public
custom form property.


--
Albert D. Kallal (MVP)
Edmonton, Alberta Canada
(e-mail address removed)
http://www.attcanada.net/~kallal.msn


djc said:
I am declaring a dynamic array variable using Public keyword in the
declarations sections of a form. I need it to be available to another form
that is called from this form.

Public TestArray() As String

I get this error when trying to doing anything... at any event on the form:

"The expression on 'insert any event here' you entered as the event property
setting produced the following error: Constants, fixed length strings,
arrays, user defined types, and declare statements not allowed as public
members of object modules." It goes on further to say:

"The expression may not result in the name of a macro , the name of a
user-defined function, or [event procedure]. There may have been an error
evaluating the function, event, or macro"

Whats this about? What did I do wrong? Can't I make a public array variable?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top