ArtinSoft's Blogs

Software Migration Experts
Welcome to ArtinSoft's Blogs Sign in | Join | Help
in Search

Jose Aguilar's Blog

All things migrations, software and technology

February 2010 - Posts

  • Error Handling Customizations

    One very common requirement for migration projects is to adapt certain error handling patterns used in a customer’s Visual Basic 6.0 code to the structured error handling provided by .NET, cleaning up the code, improving its maintainability, and, whenever possible, complying with .NET best practices.

    The VBUC already converts several commonly used error handling patterns, such as the ones described in this old post. There are, however, situations where the VBUC is not able to recognize a pattern. these usually involve Goto statements, On Error Resume Next, Resume Next or some other construct usually associated with “spaghetti code”. When one of these patterns is encountered, the VBUC does a very basic transformation and generates an EWI so it can be cleaned up through manual intervention later on, such as in the following example:

    Visual Basic 6.0 Code

    .NET Code

    Private Function <NAME>(<PARAMS>) As <TYPE> 
      Const MethodName As String = "<NAME>" 
           On Error GoTo ErrorLabel 
           <STATEMENTS 1> 
           On Error GoTo <LABEL> 
           <STATEMENTS 2> 
      CleanUp: 
           <STATEMENTS 3> 
           Exit Function 
                    
      <LABEL>: 
           <STATEMENTS 4>       
           LogError(MethodName) 
           Err.Raise 16, , MethodName 
                    
       ErrorLabel: 
           <STATEMENTS 5> 
           LogError(MethodName) 
           Err.Raise Err.Number, , MethodName 
    
    End Function 
     
    private <TYPE> <NAME>() 
    { 
    
    const string MethodName = "<NAME>"; 
    //UPGRADE_TODO: (1065) 
    Error handling statement
    (On Error Goto) could not be converted. More Information:
    http://www.vbtonet.com/ewis/ewi1065.aspx
    NotUpgradedHelper.NotifyNotUpgradedElement( "On Error Goto Label (ErrorLabel)"); <STATEMENTS 1> try { <STATEMENTS 2> <STATEMENTS 3> return result; } catch (Exception ex) { <STATEMENTS 4> LogError(MethodName); throw new System.Exception( ((int) 16).ToString() + ", " + String.Empty + ", " + MethodName); ErrorLabel: <STATEMENTS 5> //UPGRADE_WARNING: (2081)
    Err.Number has a new behavior.
    More Information:
    http://www.vbtonet.com/ewis/ewi2081.aspx
    LogError(MethodName); throw new System.Exception( Information.Err().Number.ToString() + ", " + String.Empty + ", " + MethodName); return result; } }

    Most of the time it is possible to generate a solution that will correctly convert the error handling pattern, maintaining functional equivalence and meeting any additional coding guidelines from our customers. For the previous example, The VBUC can be customized so the generated code looks as follows:

    try 
    { 
           try 
           { 
                  <STATEMENTS 1> 
           } 
           catch (Exception ex){ 
                  <STATEMENTS 5> 
                  throw; 
           } 
           try 
           { 
                  <STATEMENTS 2> 
           } 
           catch (Exception <LABEL>Ex) 
           { 
                  <STATEMENTS 4> 
                  <LABEL>Ex.Data.Add("ERROR",16); 
                  throw; 
           } 
    } 
    finally 
    { 
           <STATEMENTS 3> 
    }

    This example makes some assumptions on the nature of the code and on the intention of the original VB6.0 developer, in particular:

    • Errors raised by  <STATEMENTS 1> should be handled by <STATEMENTS 5>
    • Errors raised by  <STATEMENTS 2> should be handled by <STATEMENTS 4>
    • <STATEMENTS 3> is cleanup code that should always be executed
    • The Exception needs to be thrown again without loosing any information

    This is just an example, but the intention is to show what type of customizations can be done. The VBUC transformation engine is very powerful, and, as long as a pattern can be identified, can help you automate the solution to most VB6.0 problems.

  • Revisiting Windows 7 XP Mode

    Back when it was first announced I made a couple of posts about Windows 7 XP Mode (available here and here). Now that I’ve been using almost every day for the past few months, I wanted to revisit the topic and write about my hands-on impressions. In this post I’ll show how applications that run under XP Mode integrate with the regular Windows 7 environment.

    The integration features of XP Mode work really well, for the most part. Applications installed in the Virtual Machine appear right there on the Start Menu:

     XPM01 
    The Start menu gains a “Windows XP Mode Applications” folder under “Windows Virtual PC”,
    which holds all apps installed in the XP  Mode virtual machine (click picture to enlarge)

    And even show up when searching, which is extremely convenient.

     XPM02
    The Quick Search functionality of the Start menu covers
    XP Mode Applications. (click picture to enlarge)

    When you launch applications, Windows starts up the XP Mode virtual machine behind the scenes, showing a progress toolbar instead of XP’s boot up sequence.

    XPM03
    Windows XP Mode virtual machine startup. Notice it is running under
    Windows Virtual PC. (click picture to enlarge)

    Once the application starts up, you’ll notice it is running on XP Mode since the UI uses XP’s windows, instead of Aero:

    XPM04
    Visual Basic 6.0 on XP mode, complete with default Windows XP “Luna” theme. (click picture to enlarge)

    The following screenshot shows this more clearly, by contrasting the Visual Basic 6.0 IDE running under XP Mode and Visual Studio 2008 running directly on the Windows 7 desktop.:

    XPM05
    Visual Basic 6.0 on XP mode (Luna theme) vs. Visual Studio 2008
    on Windows 7 (Aero Glass theme). (click picture to enlarge)

    Another VERY NICE feature is that the "My Documents” folder is transparently mapped to Windows 7’s “Documents” library:

    XPM06 
    Visual Basic 6.0 on XP mode Open Project dialog showing the My Documents folder.
    Notice the same contents on the Documents library in Windows 7. (click picture to enlarge)

    These integration features of XP Mode make life much easier for legacy applications, but it is far from perfect. In the next post I’ll mention the annoyances I’ve run into while working with XP Mode.

This Blog

Syndication

Powered by Community Server (Non-Commercial Edition), by Telligent Systems