It is often necessary to exclude a group of VB6 statements from the migration process, or to specify a different set of statements for the .NET application. VB Migration Partner gives you many options for excluding a portion of VB6 code or specifying a different set of statements.
The simplest way to hide a group of VB6 statements from the migration process is by preceding them with a ParseMode Off pragma, as in this example:
Alternatively, you can use the ParseMode Remarks pragma, in which case the excluded statements appear in the .NET project as commented out code. Both the ParseMode Off and ParseMode Remarks pragmas support a second argument, the number of statements to be excluded or commented, which is quite handy to exclude just one or two statements. For example, this VB6 code:
translates to the following .NET code:
// IGNORED: DoSomething 123
In addition to excluding a portion of VB6 code, you can also include VB.NET or C# code, by means of the InsertStatement pragma, which simply emits its argument in the code produced by VB Migration Partner. Or you can use the ReplaceStatement to replace an individual VB6 statement with a VB.NET or C# statement. For example, assume that you must call the DoSomething method with the argument 123 under VB6 and with the argument 456 under VB.NET. This code does the trick:
The argument of the InsertStatement and ReplaceStatement pragmas is emitted verbatim: VB Migration Partner doesn’t process the argument and the code you emit must be a valid VB.NET or C# statement, else a compilation error occurs when the code runs in Visual Studio. For this reason, if you are converting to C# the pragma should including a trailing semicolon:
A third technique to exclude or include a portion of code in the migration process is by means of the VBC_VER compilation constant. Such a constant is undefined in VB6 and is equal to 8 in VB2005 or later version (and is correctly recognized by VB Migration Partner), thus you can write VB6 code such as this:
#If VBC_VER = 8 Then
This last technique is especially effective when including a large portion of .NET code. Notice that, unlike the InsertStatement pragma, the VB6 code in the “true” portion of the #If block is correctly parsed and migrated by VB Migration Partner. It is therefore necessary that the code in the block contains valid VB6 statements.
A fourth technique is based on the OutputMode pragma, which allows you to uncomment a block of remark lines. You can therefore insert a block of commented VB.NET statements and have them uncommented when the output file is generated:
The uncommented code must contain valid .NET statements. For example, when converting to C# the above code should be written as follows:
Finally, if the amount of VB.NET code to be inserted isn’t negligible, you can store it in a text file and use a PostInclude pragma to include it in a specific point of the converted application: