TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > VB.NET

Notices

Setting Text on Different Form

VB.NET


Reply
 
Thread Tools Display Modes
Old 15-12-2007, 03:28 AM   #1
Fred
Guest
 
Posts: n/a
Setting Text on Different Form

I have two forms, the first having a label and a button that opens the
second form. The second form has a button that I want to set text in
form1's label before closing.
I have no problem getting the 2nd form to show, but when I click the
2nd form's button to set the text in the 1st form's label, I get the
following message:
Object reference not set to an instance of an object.
What am I doing wrong????
  Reply With Quote
Old 15-12-2007, 03:28 AM   #2
zacks@construction-imaging.com
Guest
 
Posts: n/a
Re: Setting Text on Different Form

On Dec 14, 4:01 pm, Fred <> wrote:
> I have two forms, the first having a label and a button that opens the
> second form. The second form has a button that I want to set text in
> form1's label before closing.
> I have no problem getting the 2nd form to show, but when I click the
> 2nd form's button to set the text in the 1st form's label, I get the
> following message:
> Object reference not set to an instance of an object.
> What am I doing wrong????


If the 1st form the application's main form? If so how is it shown? Is
it being shown because it is the project's startup object? If so, then
the reference to the form will not be known to any other class in the
project. If the application's startup object is a Sub Main, and the
form is shown by invoking the Application.Run method in the Sub Main
and passing a reference to the main form to the Applicaiton.Run
method, then it becomes a global reference where any other class in
the project can access it, and any Public or Friend object in it.
Controls in VB are declared as Friend by default.
  Reply With Quote
Old 15-12-2007, 03:29 AM   #3
ShaneO
Guest
 
Posts: n/a
Re: Setting Text on Different Form

Fred wrote:
> I have two forms, the first having a label and a button that opens the
> second form. The second form has a button that I want to set text in
> form1's label before closing.
> I have no problem getting the 2nd form to show, but when I click the
> 2nd form's button to set the text in the 1st form's label, I get the
> following message:
> Object reference not set to an instance of an object.
> What am I doing wrong????


In Form2, prefix the label with the Form Name -

Form1.Label1.Text = "Hello"


ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
  Reply With Quote
Old 15-12-2007, 06:18 AM   #4
Fred
Guest
 
Posts: n/a
Re: Setting Text on Different Form

On Dec 14, 4:12 pm, wrote:
> On Dec 14, 4:01 pm, Fred <> wrote:
>
> > I have two forms, the first having a label and a button that opens the
> > second form. The second form has a button that I want to set text in
> > form1's label before closing.
> > I have no problem getting the 2nd form to show, but when I click the
> > 2nd form's button to set the text in the 1st form's label, I get the
> > following message:
> > Object reference not set to an instance of an object.
> > What am I doing wrong????

>
> If the 1st form the application's main form? If so how is it shown? Is
> it being shown because it is the project's startup object? If so, then
> the reference to the form will not be known to any other class in the
> project. If the application's startup object is a Sub Main, and the
> form is shown by invoking the Application.Run method in the Sub Main
> and passing a reference to the main form to the Applicaiton.Run
> method, then it becomes a global reference where any other class in
> the project can access it, and any Public or Friend object in it.
> Controls in VB are declared as Friend by default.


>

I have a Sub Main start-up w/ Application.Run(frmMain) as the means of
showing the first form. Once the frmMain form is shown, I am able to
show the second form with a button click event.
The second form has the button click event coded with:
frmMain.lblTitle.Text = "Form 2 Closed"
Me.Close

It is the frmMain.lblTitle.Text = "Form 2 Closed" that is identified
as the source of the error. This is driving me crazy!
  Reply With Quote
Reply

Thread Tools
Display Modes



< Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 07:21 PM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional