473,325 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Problem transporting info from 1 form to another

I have two form and I want to display in the first form some of the info from
the second one. Here is how I tried to do it:

<<<<ok button of form2>>>>>
Dim Myform1 As New Form1
Myform1.Label1.Text = TextBox1.Text
'label1 is in the first form

well, it seems very simple but my program does not want to update the
information of the first form. I guess I'm doing something wrong but what ??

Thank you for your help
--
Jean Bilheux, PhD
Oak Ridge National Laboratory
Jul 21 '05 #1
2 1322

Jean wrote:
I have two form and I want to display in the first form some of the info from the second one. Here is how I tried to do it:

<<<<ok button of form2>>>>>
Dim Myform1 As New Form1
Myform1.Label1.Text = TextBox1.Text


These lines create a brand new Form1 and do not access the text box on
the original form1.
Just like any other class, you need to have a reference to Form1 inside
the second form in order to access its properties or methods. One way
is to have your app start with a Sub Main, then create a global
variable to hold the reference to your first form. Something like
this:

Public MainForm As Form1

Public Sub Main()
MainForm = New Form1
Application.Run(MainForm)
End Sub

Another method is to pass in a reference to Form1 into Form2 using an
overloaded constructor, you can then access the variable throughout
form 2.

<< In button click on Form1 >>

Dim MyForm2 As New Form2(Me)

<< In Form2 >>

Private Form1Reference As Form1

Public Sub Form2(formref As Form1)
Form1Reference = formref
End Sub

Hope this gives you some ideas,

Chris

Jul 21 '05 #2
That was all I need to know.
thanks a lot

"Chris Dunaway" wrote:

Jean wrote:
I have two form and I want to display in the first form some of the

info from
the second one. Here is how I tried to do it:

<<<<ok button of form2>>>>>
Dim Myform1 As New Form1
Myform1.Label1.Text = TextBox1.Text


These lines create a brand new Form1 and do not access the text box on
the original form1.
Just like any other class, you need to have a reference to Form1 inside
the second form in order to access its properties or methods. One way
is to have your app start with a Sub Main, then create a global
variable to hold the reference to your first form. Something like
this:

Public MainForm As Form1

Public Sub Main()
MainForm = New Form1
Application.Run(MainForm)
End Sub

Another method is to pass in a reference to Form1 into Form2 using an
overloaded constructor, you can then access the variable throughout
form 2.

<< In button click on Form1 >>

Dim MyForm2 As New Form2(Me)

<< In Form2 >>

Private Form1Reference As Form1

Public Sub Form2(formref As Form1)
Form1Reference = formref
End Sub

Hope this gives you some ideas,

Chris

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Páll Ólafsson | last post by:
Hi I have a problem with the Microsoft.ApplicationBlocks.ExceptionManagement? I can't get it to work in RELEASE mode? If I run the project in debug mode the block works fine but when I run the...
3
by: Rob | last post by:
I have a vb form which calls a thread which makes webrequest calls into the internet, processes the info, and passes the info to another routine in another sub. It is stopping when it tries to make...
248
by: Generic Usenet Account | last post by:
As per Google's Usenet archives http://groups.google.com/googlegroups/archive_announce_20.html], the first discussion of the Y2K problem on the Usenet was on January 18 1985...
0
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode...
2
by: Jean | last post by:
I have two form and I want to display in the first form some of the info from the second one. Here is how I tried to do it: <<<<ok button of form2>>>>> Dim Myform1 As New Form1...
6
by: chris | last post by:
My code <?php $name = "freddie"; $message.="Hi Joe,\n"; $message.="\t $name has Filled out the form on the Website,\n"; $message.="The information from the form is listed below:\n";...
9
by: esakal | last post by:
Hello, I'm programming an application based on CAB infrastructure in the client side (c# .net 2005) Since my application must be sequencally, i wrote all the code in the UI thread. my...
2
by: Ron | last post by:
Hi All, I've got a main form (frmMain) with 5 subforms on it. All subforms are linked to different hidden controls on frmMain. The purpose of this form is to record payments by 'source'...
4
by: szimek | last post by:
Hi, I've already posted an email with this problem, but this time I think I got a bit more info. The app I'm currently working on works like this: when user clicks on a clickable element, it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.