Solved

Reusable code in Class Library and Forms

Posted on 2013-11-04
3
311 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

19 Experts available now in Live!

Get 1:1 Help Now