Any project that you create in Visual Basic can contain reusable classes. The project type determines how the classes are used. Before you create a class, think about the type of project in which it belongs.
There are seven types of projects you can create in Visual Basic. Table 20.1 lists these types and when to use them.
Table 20.1 - Types of Projects and Their Uses
Project Type | Public? | Use to Create |
---|---|---|
Standard .EXE | No | A general application that does not share components |
ActiveX .EXE | Yes | A shared component that runs in a separate process |
ActiveX DLL | Yes | A shared component that runs within the caller's process |
ActiveX control | Yes | A visual component for use within Visual Basic, Visual C++, and other OCX-compliant applications |
Add-In | Yes | A tool that can be loaded in the Visual Basic development environment |
ActiveX document .EXE | Yes | An application that runs in Internet Explorer or other hosting environments |
ActiveX document DLL | Yes | A shared component that runs within Internet Explorer |
Of the project types listed in Table 20.1, only the Standard .EXE is completely private; that is, it does not provide classes for reuse in other applications. All other types of projects can contain both private and public classes.
This creates a special case for Standard .EXEs. With other project types, classes have an Instancing property that controls how new objects are created; with Standard .EXE projects, the Instancing property is not available - all classes are private. Table 20.2 shows what Instancing settings are available from different project types.
Table 20.2 - Available Instancing Property Settings by Project Type
Instancing Setting | Standard .EXE | ActiveX .EXE | ActiveX DLL | ActiveX Control | Add-In | Document .EXE | Document DLL |
---|---|---|---|---|---|---|---|
1 - Private | X | X | X | X | X | X | X |
2 - PublicNotCreatable | X | X | X | X | X | X | |
3 - SingleUse | X | X | X | ||||
4 - GlobalSingleUse | X | X | X | ||||
5 - MultiUse | X | X | X | X | X | ||
6 - GlobalMultiUse | X | X | X | X | X |
Be sure to choose a project type that allows the type of classes you want to create. You can change project type at any time, but sometimes doing so means that other settings will change as well. The terms used in the Instancing settings list have special meanings: