Creating Classes & ActiveX Controls

Creating a class

When creating a new class you have a number of options:

1) Create a new ActiveX DLL project, and add classes to that. This will then be compiled into a DLL, which can then be used by multiple projects.

2) Just add a new class to your current EXE project. This will be included into your EXE, and cannot be used by other projects.

To create a new ActiveX DLL project:

1) Select File|Add Project, and double click on ActiveX DLL. A new project is added to your project group.

2) A class is automatically added to the DLL project for you.

3) Give the project a suitable name

4) Set its Instancing property:

Private - Only available inside this DLL project (cannot be accessed by another project)

Multiuse - Can be created as a new object in another project (see Classes and Controls above). Class is loaded when first used

Global Multiuse - Methods and properties can be accessed from another project like any other VB function (ie Msgbox). Class is loaded when the project that is using it starts.

5) Reference the DLL project to your other EXE project. Select your EXE project, and click Project|References. Check the box next to the name of your DLL project. Your EXE project now knows that the DLL project exists, and can use its classes.

To add a new class to your current EXE project:

1) Select Project|Add Class Module, and double click on Class Module.

2) A new class is added to your project.

Then give the class a good name that means something:

f123x - not a good name. What's it for? Is it a class, control, form or a module?

FileFunctions - getting there. This contains file functions. Is it a class, control, form or a module?

clsFileFunctions - good! This is a class (cls) that contains file functions.

You are now ready to create some methods, properties and constants. The next few sections show you how. Where you see User Control, change it in your mind to Class Module, as they are essientially the same, except the Class Module has no interface and no controls. It can still have properties, methods and constants.

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.” - Rick Osborne