Using Custom Maps in the VBUC to change class names

28. September 2009 10:28 by Mrojas in General  //  Tags:   //   Comments (0)

The VBUC has a now a nice feature called CustomMaps.This feature allow the users to perform basic customizations in the way the target code is generated.

During migration the VBUC can perform some name changes due to the Keyword restrictions in .NET.

For example  VB.NET the some of the following keywords that cannot be used as class or variable names:

Interface, Alias, And, Class, Error, Friend, Loop, MyBase, MyClass, Shared, Property

See here for a list of all VB.Net keywords.

1. Open the Artinsoft VBUC

 

2.  Go to the Tools Menu\Custom Maps Editor

image

The Custom Maps Editor dialog will show up.

 

3.  In the Custom Maps Editor select New...

image

 

4.  Type a name and description for your custom map.

image

5. Create some Custom Maps lines.

Follow these steps:


a. First type a new SourceName. The source name is used by the VBUC to identify the element that you want to map.
NOTE: If you are migrating just one Project, you just enter one custom maps line with the the source name of the class you want to rename. If your are migrating several project you must enter an additional line like <ProjectName>.<ClassName> for example Project1.Interface that is because for other projects that have Project1 as a Reference they see that class as Project1.Interface and not just Interface.

image

 

b. Set the Map Type. For classes we call it a Type Map. For Functions, Subs or Properties we call it a member map.

image

 

c. We now change the New Reference Name. For a class we call a “Reference Name” to every time a the class is used to define a variable. For example each Dim x as Class1, or every appearance as a parameter, like Sub Foo(x as Class1).
image

 

d. We set the Reference Action to Modify.

image

 

e. And we set the NewDeclarationName to InterfaceClass and the DeclarationAction to Modify

image

 

f.  To make sure that Keyword renamed declarations are mapped with your custom maps configuration, you have to add a line just the same as the one you had just entered but type Interface_Renamed in the SourceName

image

 

6. Now you have to activate it in your profile. Click on the Edit button for profiles in the main VBUC window

image

 

7. If you don’t have a Profile now, In the Profile Maintenance Dialog click New, and type a name for your Profile.

image

 

8. In your profile Select the custom maps configuration you just created:

image

9. Now Upgrade all your code.

VB6 Declarations like:

image

will be migrated as:

Option Strict Off
Option Explicit On
Imports System
Friend Partial Class Form1
    Inherits System.Windows.Forms.Form
    'UPGRADE_WARNING: (2080) Form_Load event was upgraded to Form_Load event and has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2080.aspx
    Private Sub Form1_Load(ByVal eventSender As Object, ByVal eventArgs As EventArgs) Handles MyBase.Load
        Dim y As InterfaceClass
    End Sub
    Sub Foo(ByRef x As InterfaceClass) 

    End Sub
End Class

And the class definition to:

Option Strict Off 
Option Explicit On 
Imports System 
Friend Class InterfaceClass 
End Class