Solved

Reusable code in Class Library and Forms

Posted on 2013-11-04
3
310 Views
Last Modified: 2013-11-05
I am creating an application which has multiple smaller applications (exe)s to make up the larger framework.  Can I use DLLs (Class Libraries in VB.NET?  When I work on one of the sub-applications how can I access a form's controls in another application.  The main example here would be the main application.  It basically resides in the background calling the other apps.
0
Comment
Question by:Peter Allen
3 Comments
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 39622890
Yes you can create class library and put any of the common methods there. To access them you simply have to add IMPORTS <library name> at the top of the page that needs to access the methods.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 350 total points
ID: 39623294
You can reference a Form in a dll or in a exe if you follow a few simple rules. For the sake of simplicity I will use dll, but everything I say here about dll also works with an exe.

By default, controls are defined as Friend, which means that can be used only from inside the project where they reside. Your main application being in another project than the dll, it would not be able to access the controls. If you want to be able to use a given control in your application, change its Modifier property to Public in the dll.

In the application, make sure that you reference the dll through Project...Add Reference.

You will then be able to work with anything that is declared Public in the dll: Public forms, Public modules, Public methods, Public controls.

For a form, in the application, instanciate your form dll, using the namespace of the dll followed by the name of the form. The namespace is the name of the dll by default, but can be changed in the dll project's Properties window, in the Application tab, as the Root namespace.

Dim frm as New YourDllNamespace.YourFormName
0
 

Author Closing Comment

by:Peter Allen
ID: 39624686
Thank you very much for the explanation.  Very clear.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now