English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Okay, i have a Form (Form1) in my vb project, with some text boxes and a button. Now, when the button is clicked it does an equation.

How can i get the equation result into my controls on Form2?

2006-11-28 21:09:11 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

4 answers

Was Form1 created by a method in Form2 - or vice versa?

If so, you could pass a reference of the one form to the other via the Form's constructor. Let's assume that Form1 creates and calls Form2:

In Form2: (New Method)
------------------------------------------------
Private MyParent As Form1 '<--- Reference to Form1

Public Sub New(Parent As Form1)
InitializeComponents ' <--- This has to be here
MyParent = Parent ' <--- Storing the reference for later use!
End Sub
------------------------------------------------
In Form1: (This is the creation of Form2)
------------------------------------------------
Dim NewForm As New Form2(Me)
NewForm.Show()
------------------------------------------------
Then when you want to send the info back to the other form, you have a reference to it:

MyParent.TextBox1.Text = Whatever

------------------------------------------------

If Form1 does not directly create Form2 (or vice versa), they can find eachother through a common ancestor... and they MUST have a common ancestor since all the forms were launched by a single application.

In my humble opinion, using a global variable to do this common task is a bit of a kludge - so learn the right way to do it! When you start writing applications of any size, you'll see that global variables turn out to be a horrible way to pass information.

If you need more detailed help, I'd be happy to offer it up!

2006-12-02 15:12:41 · answer #1 · answered by Ryan Z 2 · 0 0

Wow...... it's been a while since I've done VB. If I remember right you need a module to handle global variables, then on the form2's load event you can recall the variable. Use the module as a buffer, such as the line immediately before form2 is opened assign the variable in form1 to the global so that when form2 is loaded it's ready to recall.

2006-11-28 21:33:47 · answer #2 · answered by makr8100 1 · 0 0

Create a public class with a shared member like

Class myclass
shared var
end class

Assign it the calculated value and then access it on some other form...

2006-11-28 21:39:49 · answer #3 · answered by Vaibhav 4 · 0 0

my.form2.control.textbox1.text = equation_result

Cheers !!!!

2006-11-28 21:35:48 · answer #4 · answered by Seven double O 3 · 0 0

fedest.com, questions and answers