I do recommend using constructor to pass data from form to form. Just
initalize the new form with the data you need to pass and handle them in the
constructor of the newly launched form. In C#, it looks like this:
MyNewForm newForm=new MyNewForm(Info1,Info2);
newForm.Show();
In MyNewForm:
public MyNewForm(string Info1, string Info2)
{
#assign value of Info1 and Info2 to their respective variable
}
cheers,
yizhe
"Sean Hederman" wrote:
"Guy" <Gu*@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.com... Hi,
I'm working in vb.net and have one form that creates a second form. I need
the first form pass info to the second form.
I prefer to use the form constructor to send in any information the form may
need.
Dim f2 As New Form2(myData);
I tried using a shared property in the first form and got this error :
Cannot refer to an instance member of a class from within a shared method
or
shared member initializer without an explicit instance of the class.
A shared member can only talk to other shared members directly.
I changed the shared property to public and got this error :
Reference to a non-shared member requires an object reference.
One of the members is still shared.
Does anyone know how I could do this?
You have to pass some data around at some point. Now it doesn't really make
much sense having the variables shared since then they have class scope
rather than instance scope, and I assume you're trying to access instance
data. Thus, if you don't want to use the constructor option above you can
use liu's suggestion, just make sure that none of the variables or methods
setting them are Shared.
Thanks,
Guy