Note: this article only applies to conversions to VB.NET.
If a VB6 class has a method with a Friend scope and the class is implemented as an interface, the following compilation error can appear after the conversion to VB.NET:
Method 'XYZ' not found
For example, consider a VB6 class named Rectangle:
Friend Sub Init(ByVal width As Single, ByVal height As Single)
End Sub
Let’s further assume that the VB6 application includes a Square class defined as follows:
Implements Rectangle
The Implements Rectangle statement forces VB Migration Partner to render Rectangle as an interface and to rename the original Rectangle class as RectangleClass:
Public Class RectangleClass
Implements Rectangle
Friend Sub Init(width As Single, height As Single)
End Sub
End Class
Finally, assume that elsewhere in the VB6 project you have the following method:
Function GetRectangle(ByVal width As Single, ByVal height As Single) As Rectangle
Set GetRectangle = New Rectangle
GetRectangle.Init width, height
End Function
Here’s how VB Migration Partner translates the GetRectangle method to VB.NET:
Function GetRectangle(ByVal width As Single, ByVal height As Single) As Rectangle
GetRectangle = New RectangleClass()
GetRectangle.Init(width, height)
End Function
Here’s the problem: the GetRectangle local variable contains a pointer to the Rectangle interface, not to the RectangleClass concrete class. The Init method has a Friend scope and isn’t part of the Rectangle interface, therefore it can’t be reached through the reference in the GetRectangle variable. You can solve this problem by slightly tweaking the VB6 code, as follows:
Function GetRectangle(ByVal width As Single, ByVal height As Single) As Rectangle
Dim rect As New Rectangle
rect.Init width, height
Set GetRectangle = rect
End Function
which translates to the following VB.NET code:
Function GetRectangle(ByVal width As Single, ByVal height As Single) As Rectangle
Dim rect As New RectangleClass()
rect.Init(width, height)
Return rect
End Function
This code compiles and runs correctly.