Previous | Index | Next 

[HOWTO] Replace App6 properties with native VB.NET members

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

VB Migration Partner replaces the VB6 App object with the special App6 object, as in the following examples:

        lblCopyright.Version = App6.Major & "." & App6.Minor & App6.Revision

Most of the App6 members, however, are just wrappers around .NET Framework methods or properties of the My.Application.Info object, thus you might prefer to see the native .NET members in the generated code. VB Migration Partner doesn’t do the replacement automatically, but you can force it yourself with a bunch of PostProcess pragmas:

        '## PostProcess "\bApp6.EXEName\b", "My.Application.Info.AssemblyName"
        '## PostProcess "\bApp6.Path\b", "My.Application.Info.DirectoryPath"
        '## PostProcess "\bApp6.hInstance\b", "Process.GetCurrentProcess().ID"
        '## PostProcess "\bApp6.Comments\b", "My.Application.Info.Description"
        '## PostProcess "\bApp6.CompanyName\b", "My.Application.Info.CompanyName"
        '## PostProcess "\bApp6.FileDescription\b", "My.Application.Info.Title"
        '## PostProcess "\bApp6.LegalCopyright\b", "My.Application.Info.Copyright"
        '## PostProcess "\bApp6.LegalTrademarks\b", "My.Application.Info.Trademark"
        '## PostProcess "\bApp6.Major\b", "My.Application.Info.Version.Major"
        '## PostProcess "\bApp6.Minor\b", "My.Application.Info.Version.Minor"
        '## PostProcess "\bApp6.Revision\b", "My.Application.Info.Version.Build"
        '## PostProcess "\bApp6.ThreadID\b", "AppDomain.GetCurrentThreadID()"

Notice that the AppDomain.GetCurrentThreadID method is deprecated and marked as obsolete, therefore you’ll see an extra warning in the resulting VB.NET code.

App.Title property requires a more complex regular expression, because you can’t do the replacement when the property is written to:

        '## PostProcess  "(?<!\r\n[ \t]*)App6.Title(?!\s*=)",  "My.Application.Info.Title"

Message 8018 is emitted when the App.Title property is emitted; you may want to disable it:

        '## DisableMessage 8018

Finally, you can map the HelpFile, HelpContextID, and UnattendedApp properties to constants that are defined in the VisualBasic6_Support.bas module:

        '## PostProcess "\bApp6.HelpFile\b", "APP6_HELPFILE"
        '## PostProcess "\bApp6.HelpContextID\b", "APP6_HELPCONTEXTID"
        '## PostProcess "\bApp6.UnattendedApp\b", "APP6_UNATTENDEDAPP"

Remember to use the project: prefix for all these PostProcess pragmas, if you want them to apply to the entire project. Alternatively, store these pragmas in a VBMigrationPartner.pragmas file, so that you can easily apply it to all the projects you mean to convert.

 

Previous | Index | Next