Question:
Vb.Net question - Gathering variable data from another form. Please help!!!?
anonymous
2010-08-29 19:39:36 UTC
Hello,

I am a fellow VB6 coder, and I am finding the transition to VB.NET very frustrating. Here is my problem, a user clicks on a button - it opens a dialouge, the user enters the data into the form, - I want to send the data back to the original form. Should I use a loop? I made a module and made a variable that gets the data public, but, it's not working out how I intended it to.

Code: *it's just example only it wouldn't run if you copy and pasted off course.. *

toolstripbutton1_click()
formurl.show() ' show the form for the user to enter his or her data.

msgbox(myvariable) ' displays the variable blank.
end sub

I NEED TO SEND THE DATA BACK FROM MY FORM TO MY MAIN FORM... Please help!
Three answers:
Ratchetr
2010-08-29 20:13:41 UTC
Expose public properties in your form that the caller can access after the form returns.



Look at how OpenFileDialog works in vb.net.



You create a new OpenFileDialog.

You set some properties before calling ShowDialog to customize it for your needs.

If ShowDialog returns DialogResult.OK, then you extract properties in the OpenFileDialog object, e.g. FileName, to determine what the user did.



That's the standard model in .NET
Helpful Harry
2010-08-30 14:48:12 UTC
A function does return a value. And unless you use this

Dim frm as New Form2

frm.ShowDialog(me)

frm.Dispose



And you do not return a value in form2 then it will not work.



I would use properties.



'In form 1



Public Property getName

Get

Return Me.Text

End Get

Set(ByVal value)

Me.Text = value

End Set

End Property





'In form2



MsgBox(Form1.getName)

Form1.getName = "New One!"

MsgBox(Form1.getName)





Dane
Gardner
2010-08-30 06:44:44 UTC
Msgbox(Form2.Textbox1.Text)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...