![]() |
|
|||||||
| Notices |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
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???? |
|
|
|
#2 |
|
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. |
|
|
|
#3 |
|
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. |
|
|
|
#4 |
|
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! |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
< Windows Help - MS Office Help - Hardware Support >
| New To Site? | Need Help? |