returning values FROM window form

  • Thread starter Thread starter Graham Blandford
  • Start date Start date
G

Graham Blandford

Hi all,

Quickie - I hope. I already know how to use a forms New() Sub to receive
parameters from a calling class - but I don;t know how to return values...

Anyone know the recommended method for doing this?

Thanks,
Graham
 
Create some properties corresponding to each of those values, or create a
class that holds all of them and make a property of that class in your
target form.

Before that form closes, set them all...

this.FirstValueYouWantReturned = Whatever;
or me.FirstValueYouWantReturned = Whatever (vb.net)
and repeat this for each varaible. Assume these properties were added to
Form2.

So...

Form2 frm = new Form2(SomeValue, SomeOtherValue);//this means you passed in
two variables
frm.Show();

or Dim frm as Form2 = new Form2(SomeValue, SomeOtherValue)
frm.Show()

now, in form2 set those properties as I showed you above to the values you
want returned

string FirstValue = frm.FirstValueYouWantReturned;
string SecondValue = frm.SecondValueYouWantReturned;

same process for VB.NET at this point.

Or you coudl just create one property of type someClass that contains all of
the variables. Then you set them in the class (remember, it's still a
property of Form2 which is essential to either approach, this just
consolidates it).

then

string FirstValue = frm.SomeObject.FirstValueYouSet;
string SecondValue = frm.SomeObject.SecondValueYouSet;

HTH,

Bill

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
 
Thanks Bill.

I'll give it a try.


William Ryan eMVP said:
Create some properties corresponding to each of those values, or create a
class that holds all of them and make a property of that class in your
target form.

Before that form closes, set them all...

this.FirstValueYouWantReturned = Whatever;
or me.FirstValueYouWantReturned = Whatever (vb.net)
and repeat this for each varaible. Assume these properties were added to
Form2.

So...

Form2 frm = new Form2(SomeValue, SomeOtherValue);//this means you passed in
two variables
frm.Show();

or Dim frm as Form2 = new Form2(SomeValue, SomeOtherValue)
frm.Show()

now, in form2 set those properties as I showed you above to the values you
want returned

string FirstValue = frm.FirstValueYouWantReturned;
string SecondValue = frm.SecondValueYouWantReturned;

same process for VB.NET at this point.

Or you coudl just create one property of type someClass that contains all of
the variables. Then you set them in the class (remember, it's still a
property of Form2 which is essential to either approach, this just
consolidates it).

then

string FirstValue = frm.SomeObject.FirstValueYouSet;
string SecondValue = frm.SomeObject.SecondValueYouSet;

HTH,

Bill

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
 
Back
Top