Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 16th, 2005, 09:30 PM
Authorized User
 
Join Date: Nov 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Show text from Form3 Textbox1 to Form2 Textbox1

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*
__________________
Simplicity is the key
 
Old December 18th, 2005, 03:17 PM
Authorized User
 
Join Date: Aug 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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...

 
Old December 18th, 2005, 03:58 PM
Authorized User
 
Join Date: Nov 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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*
 
Old December 19th, 2005, 09:46 AM
Authorized User
 
Join Date: Aug 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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...

 
Old December 19th, 2005, 02:48 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old December 19th, 2005, 06:41 PM
Authorized User
 
Join Date: Nov 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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*






Similar Threads
Thread Thread Starter Forum Replies Last Post
Show Form2, only then run Routine1 peterasimpson VB How-To 5 April 29th, 2008 06:47 AM
How to show text in datalist while value in NULL nittin14 ASP.NET 1.0 and 1.1 Basics 4 September 1st, 2007 06:28 PM
show datagrid in Ritch Text Box??? thomaz C# 0 March 24th, 2006 05:24 PM
Show preformatedd html text mishicato BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 November 22nd, 2004 12:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.