VB Migration Partner

KNOWLEDGE BASE - Forms and controls

Previous | Index | Next 

[PRB] Private UserControls aren’t loaded with Controls.Add method

If a UserControl class has a Friend scope and isn’t visible outside the current project, it can’t be loaded by a Controls.Add method, even if this method is called from inside the current project.

The explanation: the Controls.Add (which is translated as a reference to the Controls6.Add method) requires that the UserControl be public and be flagged with a VB6Object attribute. However, VB Migration Partner doesn’t automatically add this attribute when converting a non-public UserControl.

For example, let’s suppose the current project TestProject contains a private UserControl class named AddressControl. VB Migration Partner generates the following code for this class:

        Friend Class AddressControl
        End Class

Any reference to this control inside the current project is migrated correctly. For example, if a form contains one or more occurrences of the AddressControl, these occurrences will be correctly migrated to VB.NET. However, if a form attempts to dynamically create an instance of the control by means of a Controls.Add method, the VB.NET code will throw an exception at runtime:

        Controls6.Add("AddressControl", "Address1")

To avoid this problem you have to change the class’s visibility to Public and insert a property VB6Object attribute:

        <VB6Object("TestProject.AddressControl")>  _
        Public Class AddressControl
        End Class

The simplest way to do it is by means of a PostProcess pragma at the top of the AddressControl.ctl file:

        '## PostProcess "Friend Class AddressControl",
           "<VB6Object(""TestProject.AddressControl"")> Public Class AddressControl"
Previous | Index | Next 

Follow Francesco Balena on VB6 migration’s group on


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.


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