VB Migration Partner

KNOWLEDGE BASE - Forms and controls

Previous | Index | Next 

[INFO] Arrays of menu controls can’t contain separators

VB Migration Partner supports arrays of menu controls: the program being converted can define an array of one or more elements at design time and can extend it at runtime by dynamically loading new elements. These arrays are converted into VB6ControlArray(Of VB6Menu) objects.

In VB6, a menu separator is a regular menu item whose Caption property is equal to “-“ (dash character); VB Migration Partner converts these separators into System.Windows.Forms.ToolStripSeparator objects. This conversion can occur even at runtime: in other words, VB6 code that transforms a standard menu item into a separator by assigning a “-“ character to the menu’s Caption property works fine after the conversion to VB.NET. The opposite operation – that is, transforming a separator into a regular menu item by assigning a different string to the Caption property – is also fully supported.

The only problem of menu separators is that they can’t be part of a menu array. This happens because ToolStripSeparator objects can’t belong to a VB6ControlArray objects that contains VB6Menu objects.
When migrating a menu array that contains a separator, the separator is discarded from the control array even if it retains the correct value for the Index property. The array can therefore have “holes”, thus it is recommended that you iterate over elements of a menu control array by means of a For Each loop rather than a For loop.

Another subtler malfunctioning occurs when your code processes all the elements in the control array and finds fewer elements than it expects because one or more separators have been removed from the control array.

The fact that VB Migration Partner discards separators from menu arrays becomes important if the separator was the only element of the array at design-time. (Such a menu array could be useful if the VB6 application extends the menu at runtime with information taken from a configuration file.) In such a case, the converted VB.NET application can’t compile because of the following error:
     'arrayname' isn’t a member of 'formname'
The only solution to this issue is revising the VB6 code so that the menu array contains at least one regular, non-separator item.

As explained previously, you can convert a regular menu item into a separator at runtime even if the menu item belongs to an array. For example, the following code works fine after the conversion to VB.NET:

        ' mnuArray is a control array of menu items
        Dim i As Integer
        For 1 = 0 To 15
            Load mnuArray(i)
            ' add a separator every three elements
            If (i Mod 4) = 0 Then
                mnuArray(i).Caption = "-"
                mnuArray(i).Caption = "Item #" + i
            End If
            mnuArray(i).Visible = True

This feature offers a workaround for the limitation that prevents you from adding a separator to an menu array: at design time you can define a menu that contains only standard elements, then you write code in the Form_Load event handler to assign a “-“ string to the Caption property of the elements that must become menu separators.

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