I'm realising that there's something important that I don't understand
about acccessing class properties. In fact I'm not even sure that I
can explain clearly what it is that I don't understand! But let me
try:
Let's say that I have a specific parameter value that needs to be
available to several different classes within a program. What I'm
doing currently is to store this specific value in a property of
MyClass1. This class is then instantiated in MyClass2 and then the
property is actually assigned in Form1. So (without showing the
intermediate declarations) I'd have:
Public Class Form1
dim oMyClass2 as New MyClass2
Sub etc
oMyClass2.oMyCl ass1.MyProperty = MyValue
End class
Hopefully this is OK so far.
But now say I want to access the current value of MyValue from within
a couple of other distinct classes, eg MyClass3 and MyClass4. I guess
the only way of getting at MyValue is to declare a reference to Form1
in both classes MyClass3 and MyClass4.
Public Class MyClass3
dim frm1 as New Form1
Sub etc
x3 = frm1.oMyClass2. oMyClass1.MyVal ue
End Class
and
Public Class MyClass4
dim frm1 as New Form1
Sub etc
x4 = frm1.oMyClass2. oMyClass1.MyVal ue
End Class
I'm left with 2 questions:
First, I'm a little uncertain as to whether x3 and x4 will
categorically be assigned to the same value.
Second, is there a better way of handling this? I guess with VB6 I'd
have declared a global variable that didn't need any qualification as
to which its parent class might have been. But I don't seem to have
that option with .Net
Thanks to anyone able to make sense of this.
JGD