Returning variables from new form

  • Thread starter Thread starter Billy Cormic
  • Start date Start date
B

Billy Cormic

Is there a way to launch a new form and have the new form return a
variable back to the parent form? Can this be done without the use of
global variables?

Thanks,
Billy
 
Is there a way to launch a new form and have the new form return a
variable back to the parent form? Can this be done without the use of
global variables?

Thanks,
Billy


Sure. Just add a property on the child form. Then the parent can read
that property...

Public Class ChildForm
Inherits System.Windows.Forms.Form

Private value As Integer

..............................
Do stuff that sets the value
..............................

Public ReadOnly Property Value() As Integer
Get
Return Me.value
End Get
End Property

End Class


In your main form

Public Class MainForm

Private Sub ShowTheChild()
Dim child As New ChildForm()
child.ShowDialog(Me)

Dim result As Integer = child.Value
' do stuff with value
End Sub

End Form


HTH,
Tom Shelton
 
Hi Billy, Tom,

Or do the reverse and have a method in the first Form that the second can
call.

Regards,
Fergus
 
Hi Billy, Tom,

Or do the reverse and have a method in the first Form that the second can
call.

Regards,
Fergus

That works as well :) Though I usually end up using a property and have
in fact used events to notify the parent form as well.

Tom Shelton
 
Thanks for the help.. I got it to work.

Tom Shelton said:
That works as well :) Though I usually end up using a property and have
in fact used events to notify the parent form as well.

Tom Shelton
 
Back
Top