Is it possible to convert your form to a self contained class module in vb6?
Is it possible to convert your form to a self contained class module in
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One simple way to do this is to create a new ActiveX DLL project in the VB6 IDE, and then add a new Form to the project. You also need a class, but you can just rename the default “Class1” that gets added to the project.
Create the form as you normally would, and then write a class that has a function to display the form, and optionally return information back to the caller (either via a return value, events, or public properties on the class). Once you compile the DLL, other projects can use your form by adding a reference to your DLL and instantiating the public class.
Below is a very simple example that demonstrates how you might create a generic login dialog that you can then re-use in multiple projects. The login dialog simply displays a login screen with username and password fields, and OK and Cancel buttons. A public class,
LoginDialog, can be used by other projects to actually display the login form and to retrieve data from it (the actual username and password entered by the user, and whether or not the user cancelled the dialog). The public class is a wrapper around the functionality provided by the form.Please note this is just a quick example to demonstrate the concept
Create a new Form and add it to the ActiveX DLL project. Rename it frmLogin and add the following controls to it:
Compile the ActiveX project and give it a name (i.e. MyAppLoginUI) so you can easily identify it when you need to add it to other projects.
When you want to use the form in another project, go to Project -> References… in the menu, and add your ActiveX DLL to the project. You may have to click
Browse...to find it. Below is an example of how other code might use the example login dialog we just created: