VB Migration Partner

KNOWLEDGE BASE - Forms and controls


Previous | Index | Next 

[HOWTO] Convert from OLE types to .NET types

VB Migration Partner automatically takes care of converting OLE types – such as StdPicture and StdFont objects – into the corresponding .NET types. In some cases, however, you might need to perform this conversion manually. This step can be necessary, for example, if you receive an OLE type from an external COM component or if you are to pass a .NET type to an external COM component.

VB Migration Partner’s support library contains all the methods that you need for these tasks, namely:

FromOleColor6(olecolor)
Converts from a 32-bit OLE color into a System.Drawing.Color object

ToOleColor6(netcolor)
Converts a System.Drawing.Color object into a 32-bit OLE color.

FromStdPicture6(oleimage)
Converts from a StdPicture object to a System.Drawing.Image object.

ToStdPicture6(netimage)
Convents a System.Drawing.Image object into a StdPicture object. Also supports the conversion of Icon and Cursor objects.

FromStdFont6(olefont)
Converts from a StdFont object into a System.Drawing.Font object

ToStdFont6(netfont)
Converts a System.Drawing.Font object into a StdFont object.

These methods are defined in the VBMigrationPartner_Support module as “passing methods” – that is, they just return their argument, without performing any conversion – therefore you can use these names in the original VB6 code.

For example, let’s assume that ColorPicker is a COM component that displays a color picker dialog, that you don’t plan to convert it to VB.NET (possibly because you don’t have the source code), and that this component exposes an InitColor property that takes a 32-bit OLE color. Next, consider the following VB6 code

        Dim picker As New ColorPicker
        picker.InitColor = Text1.ForeColor
        picker.Show()

The problem with this code is that the Text1.ForeColor property returns a System.Drawing.Color object, therefore the assignment throws an exception.

The simplest way to work around this problem is adding the VBMigrationPartner_Support module to the VB6 project and then wrapping the expression to the right of the = symbol in a ToOleColor6 method:

        picker.InitColor = ToOleColor6(Text1.ForeColor)

This code works well under VB6 – because ToOleColor6 is a do-nothing method – and works under VB.NET as well, because VB Migration Partner gets rid of the VBMigrationPartner_Support module and makes ToOleColor6 reference the method defined in CodeArchitects.VBLibrary.dll.

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