Udostępnij za pośrednictwem


Component Instancing Changes in Visual Basic

In Visual Basic 6.0, instance creation was controlled by the Instancing property of a class, which set both the access level (Public, Private, Friend) of a class and the way an object could be created.

In Visual Basic .NET, you set the access modifier for a class to Public, Private, or Friend, and then specify the user's ability to create instances of the class by setting the access level of the constructor (Sub New), as shown in the following table.

Visual Basic 6.0 Instancing

Visual Basic .NET

Private

Class Access attribute: Private

PublicNotCreatable

Class Access attribute: Public. Declare the constructor Friend (Friend Sub New)

SingleUse

Not supported*

GlobalSingleUse

Not supported*

MultiUse

Class Access attribute: Public. Declare the constructor Public (Public Sub New)

GlobalMultiUse

Not supported*

* There is no combination of class access and constructor access that duplicates SingleUse, GlobalSingleUse, or GlobalMultiUse. You can get an effect similar to GlobalMultiUse by importing a class into a client program, although this only makes shared members accessible without qualification. Public modules also allow a similar effect.

See Also

Concepts

Component Class Characteristics

Initialization and Termination of Components