Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo

  Returning values FROM window form (Thursday, December 23, 2004)




Found the following interesting discussion in the Newsgroups:

returning values FROM window form
by: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


 Reply:
by:William Ryan eMVP

 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/


 Reply:
by:Graham Blandford

 Thanks Bill.

I'll give it a try.


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
Add properties to the form and set the property values inside the form.

--
Herfried K. Wagner [MVP]








0 Comments:

Post a Comment

 
Previous Posts
    - Make multithreading do only X threads at a time.
    - Is it possible to execute an iSeries program from ...
    - Datagrid columns
    - XML?, INI File?, How do I do this?
    - character selection in a string
    - Split function not working.....
    - Multi-Lingual application
    - HasChanges not being updated?
    - VB6 conversion of UDT to structure - ValueType?
    - Deployment question

Archives
    - 10/03/2004 - 10/10/2004
    - 10/10/2004 - 10/17/2004
    - 10/17/2004 - 10/24/2004
    - 10/24/2004 - 10/31/2004
    - 10/31/2004 - 11/07/2004
    - 11/21/2004 - 11/28/2004
    - 11/28/2004 - 12/05/2004
    - 12/05/2004 - 12/12/2004
    - 12/12/2004 - 12/19/2004
    - 12/19/2004 - 12/26/2004
    - 12/26/2004 - 01/02/2005
    - 01/23/2005 - 01/30/2005
    - 01/01/2006 - 01/08/2006
    - 09/24/2006 - 10/01/2006

Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland