VB Migration Partner

KNOWLEDGE BASE - Language


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 




Follow Francesco Balena on VB6 migration’s group on

LinkedIn





Read Microsoft Corp’s official case study of a VB6 conversion using VB Migration Partner.




Code Architects and its partners offers remote and onsite migration services.

More details




Subscribe to our free newsletter for useful VB6 migration tips and techniques.

newsletter



To learn more about your VB6 applications, run VB6 Analyzer on your source code and send us the generated text file. You will receive a detailed report about your VB6 applications and how VB Migration Partner can help you to quickly and effectively migrate it to .NET.

Get free advice



A fully-working, time-limited Trial Edition of VB Migration Partner allows you to test it against your actual code

Get the Trial




The price of VB Migration Partner depends on the size of the VB6 application, the type of license, and other factors

Request a quote




Migrating a VB6 application in 10 easy steps

Comparing VB Migration Partner with Upgrade Wizard

Migration tools: Feature Comparison Table

All whitepapers