Help with using mutiple Forms in application converted to DLL file


When attempting to activate another Form  I received the following error message:

"Reference to a non-shared member requires an object reference"

code. from Form1 to activate for Form2:

If Form2.checkbox1.checked = True *****Error Line
.column(2).visible - False
End If

Also the "End" Command does not work when the application is converted to a DLL, what is the correct code to end the application?


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
You need to first declare a variable on Form 2:

Dim frm2 as New Form2

Form there, use frm2 whenever you want to reference the form

If frm2.checkbox1.checked = True *****Error Line
.column(2).visible - False
End If

Note that ideally, you should always work that way, in applications as well as in dlls. Calling Form2 directly was done in VB.NET to help VB6 programmers make the switch. But this forces the compiler to generate extra code to create a variable for you in the background.

This is not a very good practice, because it is then difficult to make the difference between the class Form2 (a form is a class) and the object/variable Form2 (the form that you see on the screen). This can sometimes lead to stupid bugs that are hard to understand.

You are also limiting yourself on some features. As an example, if you wanted to display 2 individual copies of the same form on the screen, you could not do it because there can be only one form called Form2. With variables referencing the form, you could have something like the following to show 2 copies of the form at the same time:

Dim frm1 As New Form2
Dim frm2 As new Form2

Doing so, you are also preparing yourself to eventually learn another .NET language. VB is the only one that I know whose compiler provides the Form2 shortcut. All other languages require that you declare a variable on a form before using it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vcharlesAuthor Commented:
Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.