Previous | Index | Next 

[PRB] Forms with same name as one of their controls can’t be opened in Visual Studio designer

In VB6 you can create a form that contains a control whose name matches the form’s name. VB Migration Partner converts these forms and the resulting application works as expected, but Visual Studio crashes if you attempt to open the form in the designer.

As a matter of fact, VB.NET lets you create a form that contains a control with same name only if you directly edit the *.Designer.vb file; if you attempt to create such a form in Visual Studio’s designer, an “Invalid Value” error message appears when you assign the duplicate name to either the form or the control.

The obvious workaround for this problem is to rename either the form or the control in the VB6 application, before attempting the migration. You can do either manually, from inside the Visual Basic 6 IDE, or by means of a PreProcess pragma. For example, suppose that you have both a form and a command button named “Save”, and you want to rename the latter into “btnSave”. Here’s the pragma you need:

        '## PreProcess "(?<!'##.+?)(?<!\"")(?<!VB\.Form\s+)(?<!New\s+)Save(?=_|\b)",
            "btnSave", False, True

The various (?<!...) portions  of the regular expression are needed to mistakenly rename the form’s name or occurrences of the “Save” string; the fourth argument is True because this pragma must affect also the hidden portion of the .frm file.

 

Previous | Index | Next