VB Migration Partner


Previous | Index | Next 

[INFO] OLE_COLOR type is converted to System.Drawing.Color

In VB6 you can defined that a variable, property, or parameter be of type OLE_COLOR, as in this code:

        Private m_ForeColor As OLE_COLOR

        Public Property Get ForeColor() As OLE_COLOR
            ForeColor = m_ForeColor
        End Property

        Public Property Let ForeColor(ByVal newValue As OLE_COLOR)
            m_ForeColor = newValue
        End Property

The OLE_COLOR type is actually nothing but a 32-bit integer, but it is a hint to VB6 that it represents a color. Consequently, VB Migration Partner converts the OLE_COLOR type into the System.Drawing.Color type.

This substitution works in all cases, except when you have an optional OLE_COLOR parameter:

        Sub SetForeColor(Optional ByVal foreColor As OLE_COLOR = vbBlue)
            foreColor = m_ForeColor
        End Sub

The problem with this code is that you can’t assign a default value to a System.Drawing.Color structure. In fact, the code that VB Migration Partner generates doesn’t compile under VB.NET:

        Sub SetForeColor(Optional ByVal foreColor As System.Drawing.Color = VBRUN.ColorConstants.vbBlue)
            foreColor = m_ForeColor
        End Sub

The current version of VB Migration Partner doesn’t allow you to fix this – admittedly rare – problem by means of pragmas. The only remedy is to edit the original VB6 code and change the OLE_COLOR parameter into a Long parameter:

        Sub SetForeColor(Optional ByVal foreColor As Long = vbBlue)
            foreColor = m_ForeColor
        End Sub

The suggested change has absolutely no effect on the way the original VB6 code behaves.

Alternatively, you might decided to preprocess the VB6 code and transforms all OLE_COLOR parameters and variables – but not properties – into plain Long values. You can do it by means of a PreProcess pragma, as in:

        '## PreProcess "(?<!\bProperty\s+(Get|Let)\b.*)As OLE_COLOR", "As Long"

Notice that you must store this text inside a *.pragmas file if you want to apply it at the project-level.

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