VB Migration Partner

KNOWLEDGE BASE - Language


Previous | Index | Next 

[INFO] .NET doesn’t support methods with same name as events

In VB6 it is legal to define a method that has the same name as an event exposed by the current form, class, or UserControl. For example, a form can expose a method named MouseMove even though the form’s base class exposes an event with same name:

 
        ' this is the MouseMove method
        Public Sub MouseMove(ByVal x As Long, ByVal y As Long)
            ' …
        End Sub

        ' this is the handler for the MouseMove event
        Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
            ' ...
        End Sub

Unfortunately, such a method definition is illegal under .NET or C#. VB Migration Partner solves the problem by marking the method with the Shadows or new keyword, as in this code:

 
        'VB.NET
        ' this is the MouseMove method
        Public Shadows Sub MouseMove(ByVal x As Integer, ByVal y As Integer)
            ' ...
        End Sub

	' this is the handler for the MouseMove event
        Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) _
              Handles MyBase.MouseMove
            ' ...
        End Sub
 
        // C#
        // this is the MouseMove method
        public new void MouseMove(int x, int y)
	{
	    // …
	}

	// this is the handler for the MouseMove event
	private void Form_MouseMove(int Button, int Shift, float X, float Y) _
	{
	    // …
	}

Thanks to this mechanism, references to the method work correctly in converted VB.NET programs. If the target method is defined in a different BAS module, VB Migration Partner solves the ambiguity by prefixing the method’s name with the module’s name:

 
        MouseMethods.MouseMove(10, 20)

(When converting to C#, method names are always prefixed by a class name if they are invoked from another class.)

Previous | Index | Next 




Follow Francesco Balena on VB6 migration’s group on

LinkedIn





Read Microsoft Corp’s official case study of a VB6 conversion using VB Migration Partner.




Code Architects and its partners offers remote and onsite migration services.

More details




Subscribe to our free newsletter for useful VB6 migration tips and techniques.

newsletter



To learn more about your VB6 applications, run VB6 Analyzer on your source code and send us the generated text file. You will receive a detailed report about your VB6 applications and how VB Migration Partner can help you to quickly and effectively migrate it to .NET.

Get free advice



A fully-working, time-limited Trial Edition of VB Migration Partner allows you to test it against your actual code

Get the Trial




The price of VB Migration Partner depends on the size of the VB6 application, the type of license, and other factors

Request a quote




Migrating a VB6 application in 10 easy steps

Comparing VB Migration Partner with Upgrade Wizard

Migration tools: Feature Comparison Table

All whitepapers