Previous | Index | Next 

[HOWTO] Avoid Option Explicit Off in generated VB.NET files

Note: this article only applies to conversions to VB.NET.

A VB6 file may or may not contain an Option Explicit directive at its top. If this directive is missing, then the VB6 developer can omit the declaration of local variables. If a local variable is omitted, its type is assumed to be Variant, or another type if a Defxxx directive is present in the same source file.

VB Migration Partner deals with Option Explicit directives in a different way. All generated VB.NET applications enforce the Option Explicit On setting at the project level, therefore no Option Explicit On directive is necessary at the file level. However, if the original VB6 file had no Option Explicit directive, then VB Migration Partner generates an Option Explicit Off directive for that file (else each undeclared local variable would cause one or more compilation errors).

Thanks to the DeclareImplicitVariables pragma, you can force VB Migration Partner to automatically generate the declarations for the local variables that were undeclared in the VB6 code. You can do this at the file- or at the project-level:

        '## project:DeclareImplicitVariables

Once you are sure that all local variables are correctly declared, you can delete the now superfluous Option Explicit Off directive by means of a PostProcess pragma:

        '## project:PostProcess "Option Explicit Off\r\n", "" 

If can include these two pragmas in the master VBMigrationPartner.pragmas file (stored in VB Migration Partner’s install folder) to ensure that this behavior applies to all the converted applications.

 

Previous | Index | Next