Scope of Public Shared

TomPhillips

Active member
Joined
Feb 24, 2005
Messages
33
Programming Experience
10+
I declare a Public Shared variable strX as string in Form frm1 and set it's value = "X".

Dim frm2 as new Form2
frm2.showdialog()

In Form2 see frm1.strX as "X"
change frm1.strX = "Y"
Close frm2

Why is strX still = "X" when I get back to frm1?

Work around: In Form2 declare Public Shared strX2 as string. Set it = "Y" then

in frm1, after frm2.showdialog()
me.strX = frm2.strX2

This seems goofy, why is Public Shared one way? You can see it and change it down scope, but when you go back up the change isn't there.
 

TPM

Well-known member
Joined
Dec 7, 2004
Messages
623
Location
CA
Programming Experience
3-5
Try : frm1.activeform.strX = "Y"
 

TomPhillips

Active member
Joined
Feb 24, 2005
Messages
33
Programming Experience
10+
OK, but then I get the error: 'strX' is not a member of 'System.Windows.Forms.Form'.
 
Top Bottom