Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie: Global Form Declaration 1

Status
Not open for further replies.

HerbAndEdnaWeinstein

Technical User
Apr 30, 2003
104
US
Hi, I've got a Form that needs to be accessed from various functions and subs in my program. (The program itself runs as an add-in to a larger app.)

So, I designed the form in the designer, named it "Form_Main", and I access it in my class declaration like this:

***************************************************
Private m_pForm_Main As New Form_Main
***************************************************

Then, from within my OnClick() sub, I invoke it like this:

***************************************************
m_pForm_Main.Show()
***************************************************

But, there's a problem. The Form works great the first time I click the start button and the Form opens. The second time I click the start button, however, the program returns an error when it attempts to open the form.

Thanks in advance, I have a feeling it's not too tough!!!
Herbie
 
A.
Code:
Private m_pForm_Main as Form_Main

B.
Code:
Try
     m_pForm_Main.Show()
Catch ex1 As System.ObjectDisposedException
     m_pForm_Main = Form_Main()
     m_pForm_Main.Show()
Catch ex2 As System.NullReferenceException
     m_pForm_Main = New Form_Main()
     m_pForm_Main.Show()
End Try
 
Right on the nose!

One more question, though (I think I can give 2 points on the same question):

I am able to update text boxes, combo boxes, and the like on the form with code like this:

*********************************************************
Form_Main.TextBox1.Text = "Here's Some Text"
*********************************************************

However, I can't figure out how to track button presses and the like, from my other class.

Thanks Again!
Herbie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top