Implementing a Method

    In Visual Basic 6 a method of a class (interface) is implemented when another class uses the keyword Implements, which indicates the class to be applied. This new class has to add a method with the new implementation of exposed methods in the interface. You have to consider that the original method in the interface could or could not have an implementation.

    The first thing that the VBUC should do to implement this feature in .NET is the generation of an interface with the declaration of the exposed members (Public), and additionally a new class, which name will be _CoClass. This class will be the first class that will implement the declared interface, and it will have the code that the class converted to interface originally had.

    In order apply a method in a class from this interface for Visual Basic .NET, the VBUC will add the keyword Implements at the end of the method, indicating which method from the interface is being implemented, and the original name of the method will be kept as source name. For C#, the VBUC just changes the name of the method removing the interface name prefix.

    Notice that the signature including modifiers, arguments and its modifiers and types, and return types must be the same as the ones from the interface.

    Original VB6 code

        
    AnInterface.cls
    
    Function IsBusy() As Boolean
        ' Code
    End Function
    
    AClass.cls
    
    Implements AnInterface
    Function AnInterface_IsBusy() As Boolean
        ' Code
    End Function
    

    VBUC resulting VB.NET code

        
    AnInterface.cls
    
    Interface AnInterface
        Function IsBusy() As Boolean
    End Interface
    Friend Class AnInterface_CoClass
        Implements AnInterface
        Public Function IsBusy() As Boolean Implements AnInterface.IsBusy
            ' Code
        End Function
    End Class
    
    AClass.cls
    
    Friend Class AClass
        Implements AnInterface
        Function AnInterface_IsBusy() As Boolean Implements AnInterface.IsBusy
            ' Code
        End Function
    End Class 
    

    VBUC resulting C#.NET code

        
    AnInterface.cls
    
        interface AnInterface
        {
            bool IsBusy();
        } 
        internal class AnInterface_CoClass
        : AnInterface
        {
            public bool IsBusy()
            {
                // Code
                return false;
            }
        }
        
    AClass.cls
    
        internal class AClass
        : AnInterface
        {
            public bool IsBusy()
            {
                // Code
                return false;
            }
        }

    Download VBUC Free Trial
    Download VBUC Now

    It's time to eradicate VB6
    ROI of eradicating VB6

    8 Proven Tips for
    Planning a Successful Migration

    8 Tips for migration