|
Subject:
|
Show text from Form3 Textbox1 to Form2 Textbox1
|
|
Posted By:
|
peterasimpson
|
Post Date:
|
12/16/2005 8:30:38 PM
|
Hiya all, I need help.
I have 3 Forms, each with a TextBox1 and a Button1. I get Button1 on Form1 to open Form2. I then get Button2 on Form2 to open Form3. On Form3 I type a message into TextBox1. I have the following code in Button1 on Form3...
Form1.TextBox1.Text = TextBox1.Text Form2.TextBox1.Text = TextBox1.Text
The problem is that the text appears in Form1.TextBox1.Text but not in Form2.TextBox1.Text.
Why is that and how do I fix the problem?
Thanks Pete*
|
|
Reply By:
|
danbush
|
Reply Date:
|
12/18/2005 2:17:53 PM
|
Peter:
It works for me. A few suggestions:
Try setting a breakpoint on the first line and run. When the debugger stops on that line, step through by line (F8) and see if it's doing what you think it should.
Make sure that you haven't set up an "On Error Resume Next" trap which would ignore any errors you have in your code.
Make sure that you have everything named the same as your code (TextBox1 instead of Text1 - the default name, etc.)
If none of this works, post all of your code so everyone can see the whole thing, not just a piece which might not be the problem...
|
|
Reply By:
|
peterasimpson
|
Reply Date:
|
12/18/2005 2:58:26 PM
|
OK. I'm using Visual Basic 2005. Just to test the code I created a new project and did what I explained above. My open Form2 and Form3 code is as follows...
Dim MyForm2 As New Form2 MyForm2.Show()
Dim MyForm3 As New Form3 MyForm3.Show()
All the code is now on this page. I could really do with somebodys help on this. Can you please post your code. I will re-write the code but in Visual Basic 2003 just to see if it works. I presume that's what you wrote it in. I'll let u know if it works in that.
Thanks again Pete*
|
|
Reply By:
|
danbush
|
Reply Date:
|
12/19/2005 8:46:54 AM
|
Peter:
Actually, I did mine in VB6. Doubt it'll translate over as easily as all that, sorry. I'm sure that along the way, they made properties of forms private or something like that...
|
|
Reply By:
|
marcostraf
|
Reply Date:
|
12/19/2005 1:48:47 PM
|
I suspect the problem is in the line: Form2.TextBox1.Text = TextBox1.Text
because you are accessing the "default" Form2 object, but in reality the instance of that form was created with the name MyForm2. Add this code in Form3:
Public m_form2 as Form2
and when you create MyForm3:
Dim MyForm3 As New Form3 set MyForm3.m_form2 = MyForm2
and change the code in the form3.button1 event to:
m_form2.TextBox1.Text = TextBox1.Text
BTW it is a very bad idea for a form to change directly another form by using the name of the components, because a small change in one form means having to change the whole project. One solution is to raise events, and let the "listeners" doing whatever they do in the event callback.
Marco
Marco
|
|
Reply By:
|
peterasimpson
|
Reply Date:
|
12/19/2005 5:41:34 PM
|
Thank u ;-) that worked. I've been trying to sort it out for a couple of days. Something so simple is sometimes really crappy to sort out.
Thanks again
Pete*
|