sharing data between forms

  • Thread starter Thread starter Al_C
  • Start date Start date
A

Al_C

As mentioned earlier I've been away from coding for about 5 years. Know I
know why :(
I've been trying to work out a critical detail, hard to do on Thanksgiving
;)
Push a button on form1, form2 appears, I enter some text push a button and
get the data back to form1.
In the "old days" we had globals to pass stuff like this through. (as a C
programmer by background
I always found that pretty poor). But now I can't find a mechanism to do
what I want. I've done a lot of MSN and google searching but nothing that
works.
(have to admit, I really need to change my Fileopen and other classic basic
code to .net)
Thanks to all, and hope you had a great day of turkey.
 
whenever i want to share info between forms, usually i create a module. i
dunno if its the rite way to do it, being only a n00b programmer at the age
of 16, but i create a new module and create a variable in the body which you
can store info in, for example

''code in module

Public strNames as String

''make it public so all forms can access it

''in your code of your form

private sub btnclick_click(...)handles...

module1.strNames = me.textbox1.text

end sub

then you can just read in the variable and write to it

hope this helps
 
Al,

There are probably thousand of possibilities.

However the first question you have to ask yourself is it
a dialogform
a normal (existing beside the other form)
a mdi (existing inside the main form)

If it is a dialogform than it is very simple and basicly

\\\
dim frm as new myform
frm.PublicValue = Mywhatever
frm.Showdialog
myWhatever = frm.PublicValue
frm.dispose
///

I hope this helps,

Cor
 
I will try to help, start by designing your main form. In the Solutions
window, right click on the solution name and click on Add, then Add Windows
Form, and name it popupForm, then add your text box and 2 buttons. Get the
physical stuff out of the way. If you start by just letting the new form be
called default 'form2.vb' then thats fine too

In the button click event to make a new form2, you would create an instance
of the form with a Dim, you get there by double clicking on the button you
created, and inside the routine type the handler, then also for button 2 add
the other handler

keeping in mind Form2 is popupForm

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim dataentry As New popupForm

dataentry.Show()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Me.TextBox1.Text = popupForm.stringarray

End Sub

Yes, technically you could create a sub to handle your new popup forms
creation and whatever, this is for example use

In the form2 or popupForm, create a textbox and a button, double click the
button

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

stringarray = Me.TextBox1.Text.ToString

End Sub

Now, do you want the text in your main form1 to change whenever text in the
other form changes? Thats far more complicated and should be part of a new
upgrade to VB release 3?

Anyhow, to update the first textbox the only way I know of is to use a thing
called an Observer Pattern. The changing data in the textbox triggers an
update event and the form1 textbox has to be subscribed by giving its
address to the event.

If anyone knows another way? Im interested to hear it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top