Export (0) Print
Expand All

Interface Statement

Declares the name of an interface, as well as the properties, methods and events that comprise the interface.

[ <attrlist> ] [ Public | Private | Protected | Friend | Protected Friend ] _
[ Shadows ] Interface name
   [ Inherits interfacename[, interfacename ]]
   [ [ Default ] Property proname ]
   [ Function memberame ]
   [ Sub memberame ]
   [ Event memberame ]
End Interface

Parts

attrlist
Optional. List of attributes that apply to this interface. Multiple attributes are separated by commas.
Public
Optional. Entities declared with the Public modifier have public access. There are no restrictions on the use of public entities.
Private
Optional. Entities declared with the Private modifier have private access. A private entity is accessible only within its declaration context, including any nested entities.
Protected
Optional. Entities declared with the Protected keyword have protected access. They are accessible only from within their own class or from a derived class. Protected access can be specified only on members of classes. It is not a superset of friend access.
Friend
Optional. Entities declared with the Friend modifier have friend access. An entity with friend access is accessible only within the program that contains the entity declaration. Interfaces that do not specify an access modifier are declared as Friend by default.
Protected Friend
Optional. Entities declared with the Protected Friend modifiers have the union of protected and friend accessibility.
Shadows
Optional. Indicates that this interface shadows an identically named programming element in a base class. You can shadow any kind of declared element with any other kind. A shadowed element is unavailable from within the derived class that shadows it, unless the shadowing element is inaccessible, for example if it is Private.
name
Required. Name of the interface; follows standard variable naming conventions.
Inherits
Optional. Specifies that the interface being declared inherits the properties and methods from the interface specified by interfacename.
interfacename
Required if optional Inherits statement is present. Indicates the name of one or more interfaces being inherited.
Default
Optional. Indicates that the property with which the Default keyword is associated is the default property for the interface.
Property
Optional. Indicates a Property procedure that is a member of the interface.
Function
Optional. Indicates a Function procedure that is a member of the interface.
Sub
Optional. Indicates a Sub procedure that is a member of the interface.
Event
Optional. Indicates an Event that is a member of the interface.
memberame
Required if optional Property, Event, Function, or Sub statements exist. Indicates the name of the property, procedure, or event.
End Interface
Terminates an Interface block.

Each attribute in the attrlist part has the following syntax and parts:

attrname [({ attrargs | attrinit })]

attrlist Parts

attrname
Required. Name of the attribute. Must be a valid Visual Basic identifier.
attrargs
Optional. List of positional arguments for this attribute. Multiple arguments are separated by commas.
attrinit
Optional. List of field or property initializers for this attribute. Multiple initializers are separated by commas.

Remarks

The methods and properties of an interface are implemented in a class. When methods are implemented, the return data type and the argument data types must exactly match those of the method described in the Interface block. The method name, however, need not be the same as that described in the Interface block. Methods being implemented in a class cannot be designated as Shared, nor can they be Private, except in a non-inheritable class.

The Interface statement can appear in the declaration section of any module. Interfaces are implicitly Friend by default but can be explicitly declared Public, Friend, Protected, Protected Friend or Private.

An interface can have, at most, one default property. This implies that an interface can either inherit only one interface containing a default property, or its definition block can contain one property that is marked as default.

An interface cannot inherit from another interface whose access level is more restrictive than its own. For example, a public interface cannot inherit a friend interface.

Example

This example uses the Interface statement to define a MyInterface interface, which must be implemented with a Property statement and a Function statement.

Public Interface MyInterface
   Property MyProp(ByVal MyStr As String)
   Function MyFunc(ByVal MyInt As Integer) As Integer
End Interface

See Also

Class Statement | Function Statement | Inherits Statement | Implements Statement | Interfaces in Visual Basic .NET | Sub Statement

Show:
© 2015 Microsoft