VB Migration Partner


Previous | Index | Next 

[PRB] The VB.NET application can’t compile because a constant in a Structure is ambiguous between two modules

Type…End Type blocks typically live inside VB6 modules and classes. When VB Migration Partner converts these blocks into VB.NET Structures, it always attempts to move the Structure outside the module it originally resided in. In very few, special cases this operation causes one or more compilation errors. More specifically, this happens if the UDT block depends on a constant that is defined inside the parent module and that the same constant is declared also in another module.

Let’s make an example to show when this problem can occur. Consider the following VB6 code, located in MyModule.cls:

        Public Type TestUDT
            FileName As String * MAX_PATH
        End Type
        Public Const MAX_PATH As Integer = 260

The above code is converted to VB.NET as follows:

        Public Structure TestUDT
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAX_PATH)> _ 
            Public FileName As VB6FixedString
            Public Sub InitializeUDT()
                FileName = New VB6FixedString(MAX_PATH)
            End Sub 
        End Structure
        Friend Module MyModule
            Public Const MAX_PATH As Short = 260
        End Module

Now, let’s further assume that the MAX_PATH constant is defined also in AnotherModule.bas. The problem: the TestUDT structure now lives outside the MyModule block, therefore the reference to the MAX_PATH constant has become ambiguous between MyModule and AnotherModule.

This is a very special case that occurs very rarely. VB Migration Partner doesn’t fix the problem automatically, however it is easy to solve the problem by means of a file-level pragma:

        '## PostProcess "\bMAX_PATH\b", "MyModule.MAX_PATH", True, False,
            "^.+\bModule MyModule"

Notice that the last argument limits the effect of the PostProcess pragma to the portion of code that precedes the Module keyword, so that references to the MAX_PATH constant inside the module aren’t affected.

Of course, you can expand the pragma to account for multiple constants, as in this example:

        '## PostProcess "\b(MAX_PATH|ARRAYSIZE)\b", "MyModule.$0", True, False,
            "^.+\bModule MyModule"
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