[quoted text clipped - 4 lines]
No, not true at all. note how KitCaz said it works just fine with variables.
Remember, a form code module is the same as a class module.
thus,
public m_setting as string
is a legal var def, and any routine can reference the above value by
supplying the forms reference, and then the var name
(assuming the form is open).
In fact, any public variable declared in a class module (including forms)
simply becomes a settable property of the form.
However, the following is NOT legal
public buf(10) as string
If kitCaz had actually tried to compile the above line of code, you see the
following error message:
---------------------------
Microsoft Visual Basic
---------------------------
Compile error:
Constants, fixed-length strings, arrays, user-defined types and Declare
statements not allowed as Public members of object modules
---------------------------
OK Help
---------------------------
(I did a control-c while viewing the dialog box to copy the above).
The simply solution is to simply declare the array as private, and then
build pubic propriety for to expose the array
in the forms code.
The following will give programming access to the array.
Option Compare Database
Option Explicit
Private vbuf() As Variant
Public Property Let myVbuf(i As Integer, str As String)
vbuf(i) = str
End Property
Public Property Get myVbuf(i As Integer) As String
myVbuf = vbuf(i)
End Property
Now, in code, you can go:
me.parent.myVbuf(3) = "hello"
msgbox "3rd value should be hello...here it is " & myvbuf(3)
So, you *can* reverence any variable declared public in a form, you just
have to supply the forms qualifier..
me.MyVariblename
or
forms!NameOfForm.MyVariableName = "hello"
or
me.Parent.MyVariableName = "hello"
Since "me" is the default, then you also use:
MyVariablename
All are above are valid.. In fact, if you have form named zoo, then if you
reference the BASE class object name of that form, inteli-sense will
actually show the above public members (variables), and also the public
property we added as a drop down list.
In code, I often start typing the follwining
msgbox forms!Zoo.varname
(and, then I goo...hum, forgot the name..I don't want to go and look it
up..so, I type in:
forms_Zoo.
----------^ ..the instaant I hit the "dot", then inti-sense will popup a
list of varilbes and properites ad public functions. I can view, or even
select the varible name...I cut otu the whole line, and the continue typeing
my orignal line of code:
msgbox forms!Zoo.MyVar.......
To make a variable truly public, you must declare it as public in a
standard
code module.
Truly pubic, yes, but as a long as the form is open, that public var in that
form is useable by ANY code and any form, or any thing in the appcation, you
just have to provide a forms qualifier.
In the posters example, he does not need a global variable, but simply to
reference a variable that is part of parents form code. Further, if KitCaz
continues to code this way, then you can even have multiple instances of the
SAME form opened..and the variables will REMAIN separate from each other.
(just like a class object would.. I you use global here , they will trip
over each over, and you can't have multiple instances of the form function
correct if you use global -- they should be avoided here);
So, I *do* in fact recommend using public variables in a forms code module
for his case.
So, the ONLY limitation here is that arrays are NOT allowed to be public in
class object, and that also applies to a forms code module which is the same
as a class object...
However, as shower, simply adding a public property to the class modules
code, you can use nearly the same syntax, and you can expose the private
array by declaring a public property.