Passing Value back from a form

  • Thread starter Thread starter robin9876
  • Start date Start date
R

robin9876

In a windows form application created in VS 2005 VB.Net I have one form
which calls another form and supplies a value. In this additional form
I need to return a value back. Below is the code to call the other
form.

Dim x As New myForm2
x.aValue = Me.TextBox1.Text
x.Show()

How can I return a value back from myForm2 back to myForm1 where the
above code is located on a button click event?
 
I would set up a property on myForm1 and have myForm2 access
the property to set it.

As for the first part, you might want to consider adding a
constructor to your myForm2 that accepts a string, and pass
that value in instead of using it as a property. This makes
it more obvious if anybody else ever uses your form, that the
value needs to be (or can be) set when creating the form.

Robin S.
 
Another solution is to declare aValue as a public member of Form2. Then
within Form1, you can directly reference x.aValue (provided you keep a
reference to x in scope).

================
Clay Burch
Syncfusion, Inc.
 
I ended up doing that by using the showdialog option from the call in
form1 to keep the form in scope until after form2 was closed.
 
Back
Top