Previous | Index | Next 

[HOWTO] Convert VB6 files that are shared among projects

VB6 allows you to share a given source file – such as a BAS module or a class in a .cls file – among multiple projects, so that you can change one file and have your edits immediately propagated to all projects. Conversely, when you add an existing file to a .NET project, by default the file is physically copied to the project’s folder and all subsequent edits are not shared with other projects.

If you want to share a file among two or more .NET projects, you must use the Add Existing Item command (from Visual Studio’s Project menu), select the file, click on the down arrow to the right of the Add button, and click on the “Add as Link” command.

When using VB Migration Partner, by default all .vb files are created in the .NET project’s folder and aren’t shared with any other project. However, creating a “linked” file is just a matter of using a couple pragmas.

Let’s assume that you are migrating a VB6 project that contains a file named Functions.bas and that is shared by other projects.

The first time you convert a VB6 project that includes the Functions.bas file you don’t need to do anything special: just convert the project and ensure that it compiles correctly under .NET. If it doesn’t, add all the pragmas that are necessary to reach the zero-compilation error stage. At this point you have a Functions.vb file that works correctly.

Next, you copy the Functions.vb file to a different location, so that it isn’t overwritten if you migrate the same project again, for example to a folder named c:\SharedFiles.
 
You can now add two more pragmas to the Functions.bas file:

        '##  ExcludeCurrentFile
        '##  AddSourceFile c:\sharedfiles\functions.vb, True

VB Migration Partner will therefore convert the Function.bas file as usual, but the file will be discarded at the end of the migration step because of the ExcludeCurrentFile pragma, and will be replaced by the file referenced by the AddSourceFile pragma. By passing True as the second argument, VB Migration Partner adds the referenced file as if the “Open as Link” command were used.

 

Previous | Index | Next