[INTERVIEW] Yours truly on .NET Rocks!

clock May 2, 2014 16:30

A few weeks ago I had an interesting and entertaining conversation with Carl Franklin and Richard Campbell of .NET ROCKS, about VB6 migration, the effect that Windows XP retirement is having on companies that can't afford keeping their mission-critical VB6 apps on an unsupported operating system, and a lot more. Yesterday the interview went online, at this URL

Happy listening!

[NEW RELEASE] Version 1.51 is available to registered users

clock June 4, 2013 11:06

Since early 2013 we have been distributing version 1.50 to selected customers, gathered their feedback and suggestions, and the result here: VB Migration Partner 1.51 is now ready.


There are tons of improvements in this new release, but the most important one is surely full-featured C# code generation. While our competitors are compatible with the C# language found in Visual Studio 2008, we decided to focus on C# 2010, which allows us to support modern C# features were not available in earlier language versions, most notably the dynamic type and optional parameters. These two single features, together with the many enhancements that only VB Migration Partner offers, let our users to create the most efficient and readable code a VB6-to-C# converter can possibly generate.

Here is a short and incomplete list of C# features offered by VB Migration Partner (and in many cases only by VB Migration Partner!):

C# specific

  • support for the dynamic type => faster and concise code
  • support for optional parameters => more readable code
  • ByRef parameters rendered using the out keyword if possible => faster code
  • the ability to generate method overloads for ref/out parameters avoids the need for temporary variables in method calls => concise and readable code
  • support for WithEvents variables => less verbose code
  • ability to implement an interface either implicitly or explicitly => compliance with your own programming style
  • transformation of On Error Goto into try-catch blocks (with warnings when the transformation isn't perfectly equivalent) 
  • transformation of On Error Resume Next into lambda expressions => full functional equivalence
  • preserves error codes => no need for manual fixes after migration
  • transformation of And/Or operators into either bit-wise or logical C# operators 
  • transformation of Select blocks into either if or switch blocks => more logical and efficient code 
  • Exit For,Do,While keywords in nested loops => code works as expected
  • expressions and function calls in compiler constants
  • string and math native .NET methods used if possible => compliance with .NET programming style 
VB.NET and C#
  • code generation for VS 2010 and VS 2012
  • support for .NET 3.5 and 4.x
  • improved support for User Control serialization in code-behind sections of forms => faster .NET form loading
  • simplified design-time and runtime support for scaling User Control at different screen resolution and system font sizes => no-brains compliance with .NET coding guidelines
  • positional pragmas: it is now possible to keep all pragma (including method-specific pragmas) in separated text files => less cluttered source files
  • automatici generation of AccessibleName property for .NET or custom controls => .NET apps ready for visually-impaired users
  • support for external source file editors => edit VB6 or .NET code with your favorite tool
  • many bugs fixed (of course!)

Each of these features (and of the many features that I didn't mentioned) would require a separate discussion, and I will surely devote some posts to the most interesting ones. 

For now, you can learn more about C# specific support here.


VB Migration Partner will support Visual Studio 2012

clock July 23, 2012 15:48

A few customers asked about our support for the forthcoming Visual Studio 2012, so here is the official announcement:

VB Migration Partner will add support for Microsoft Visual Studio 2012 within a few weeks after VS official release. This includes code generation for both VB.NET and C# and support for .NET 4.5.

A library for all .NET developers, free!

clock January 20, 2011 17:12

David McCarter, from www.dotNetTips.com, has released a new version of his open source .NET library, containing a lot of useful classes and methods. This new releases includes new features and bug fixes.

You can download it from here.

Vote for a VB6 migration session at TechEd Europe 2010

clock October 14, 2010 16:45

I submitted a BoF session at TechEd Europe 2010, entitled "VB6-to-.NET Migration: Myths, Truths, and Real-World Experiences".

There is a poll on these Birds-of-Feathers sessions, and only the ones that get most votes will be accepted.

Regardless of whether you attend TechEd, you can help by voting for my session. In addition to having me speak at TechEd, a lot of votes on this session will hopefully convince Microsoft that VB6-to-.NET migration is a hot topic and that they should invest more in that direction.

Basta! 2010 slides available

clock September 27, 2010 15:45

We just uploaded the two slide packs of my session at Basta! 2010 in Frankfurt, Germany.

VB6 to .NET Migration: Myth, Truth, and Real-World Experiences

VB6 to .NET Migration: Tips, Traps, and Techniques

Happy reading!

Two migration e-books all serious developers should read

clock September 17, 2010 10:51

In our quest to provide useful info to our users and readers, we periodically surf the Internet looking for articles, books, whitepapers, tools, etc. related to VB6 to .NET migration.

This week the search has been quite fruitful, and we have added two great items to our Articles page:

Navigating your way through Visual Basic 6.0 to Visual Basic.NET Application Upgrades
This 62-page e-book is one of the best collection of problems & solutions you can find on the Internet, with tons of detailed examples and code samples. It is obviously based on first-hand experience of the author with Microsoft Upgrade Wizard, and the solutions he proposes are valid and functional.

Visual Basic .NET Enhancements Compared to Visual Basic 6.
This e-book focuses on many differences between VB6 and VB.NET and in many cases it goes much deeper than the other articles mentioned in this page. It’s not the best place to start from when learning VB.NET, but it’s surely a must-read for the serious developer facing a complex migration project. (148 pages).

Both e-books are by David Ross Goben and are written in a clear and bright style. A must-read for all serious VB6 and VB.NET developers.

NOTE: Interestingly, virtually all the issues that David found when migrating his VB6 apps are handled automatically by our VB Migration Partner. (More on this in a subsequente post.)

A .NET library to access Windows Vista and Windows 7 features

clock September 16, 2009 21:58

One of the reasons to migrate your code to .NET is create modern user interface that take advantage of the power of newer versions of Windows. On the other hand, the .NET Framework has been designed to work in the same way over a wide range of Windows versions, including versions that are about ten years old, and therefore it doesn't provide access to the most intriguing features of Vista and Windows 7.

The solution comes in a new library from Microsoft, named Windows API Code Pack for .NET Framework. Version 1.0 of this great tool has been just released, and already implements an impressive range of Windows features:

  • Windows 7 Taskbar Jump Lists, Icon Overlay, Progress Bar, Tabbed Thumbnails, and Thumbnail Toolbars.
  • Windows 7 Libraries, Known Folders, non-file system containers.
  • Windows Shell Search API support, a hierarchy of Shell Namespace entities, and Drag and Drop functionality for Shell Objects.
  • Explorer Browser Control.
  • Shell property system.
  • Windows Vista and Windows 7 Common File Dialogs, including custom controls.
  • Windows Vista and Windows 7 Task Dialogs.
  • Direct3D 11.0, Direct3D 10.1/10.0, DXGI 1.0/1.1, Direct2D 1.0, DirectWrite, Windows Imaging Component (WIC) APIs. (DirectWrite and WIC have partial support)
  • Sensor Platform APIs
  • Extended Linguistic Services APIs
  • Power Management APIs
  • Application Restart and Recovery APIs
  • Network List Manager APIs
  • Command Link control and System defined Shell icons.
  • Shell Search API support.
  • Drag and Drop functionality for Shell objects.
  • Support for Direct3D and Direct2D interoperability.
  • Support for Typography and Font enumeration DirectWrite APIs. 

The library comes with an extensive help file and all code samples are available in both VB.NET and C#. Last but not the least, the entire source code is provided.

Pay attention to orphaned ADODB objects

clock September 2, 2009 01:26

Don't take me wrong: COM Interop is a great piece of technology, and Microsoft developers made wonders with it. If you consider how different the COM and .NET worlds are, it's a miracle that they can communicate with each other in such a smooth way.

Actually, COM Interop is such a magic that it's easy to forget that all the COM objects that we manipulate from .NET aren't the "real" COM objects. Instead, they are .NET wrappers that redirect all calls to the actual COM object by means of COM Interop. This fact has many implications. Consider for example this VB6 code:

Function GetRecordCount(ByVal cn As ADODB.Connection, ByVal sql As String) As Integer
   Dim rs As New ADODB.Recordset
   rs.Open sql, cn
   GetRecordCount = rs.RecordCount
End Function

As you see, the Recordset object isn't closed explicitly, but it isn't a problem in VB6 because all COM objects are automatically closed when they are set to Nothing or go out of scope. However, if you translate this code to VB.NET you are in trouble, because nothing happens when the method exits. In other words, you'll have an open recordset hanging somewhere in memory and cause unexplainable errors later in the application. For example, you'll get an error when you'll later try to open another recordset on the same connection.

We know that some customers had to work around this issue by enabling the MARS option with SQL Server, which enables multiple active recordsets on any given connection. This might be a viable solution if you are working with SQL Server 2005 or 2008, but VB Migration Partner offers a better way to handle this case: use the AutoDispose pragmas.

In fact, when this pragma is used, all disposable objects are correctly disposed of when they go out of scope. In this case, VB Migration Partner emits the following code:

Function GetRecordCount(ByVal cn As ADODB.Connection, ByVal sql As String) As Integer
   Dim rs As New ADODB.Recordset
      rs.Open(sql, cn)
      GetRecordCount = rs.RecordCount
   End Try
End Function

where the SetNothing6 helper method takes care of orderly invoking the Close or Dispose method, if necessary.

Can your VB6 conversion tool handle null propagation?

clock May 21, 2009 09:13

If you have massively used Variants in your VB6 apps, the migration to .NET might be a nightmare. The best that the Upgrade Wizard and other tools can do is translating each “As Variant” into “As Object”, on the assumption that the Object type can do everything that a Variant does.

You shouldn’t be surprised to learn that this is one of the false migration myths, or is a gross oversimplification of the truth, to say the least. In fact, the .NET Object type lacks what arguably is the most useful feature of Variants: support for Null values and Null propagation in expressions.

Under VB6 a Variant variable can hold the special Null value and – even more important – all the string and math expression that involve a Null operand also deliver a Null Variant value. Virtually all database-intensive applications deal with Null values and have used null propagation to an extent. Now, let’s consider this VB6 code:

' rs is an ADODB.Recordset
Dim realPrice As Variant
realPrice = rs("Price")
realPrice = realPrice * (100 – rs("Discount")) / 100
If Not IsNull(realPrice) Then DisplayPrice(realPrice)

Under VB6, if either the Price or the Discount field is Null, the realPrice variable is assigned Null and the DisplayPrice method isn’t invoked. Now, consider the “canonical” VB.NET version of the above code:

Dim realPrice As Object
realPrice = rs.Fields("Price").Value
realPrice = realPrice * (100 – rs.Fields("Discount").Value) / 100
If Not IsNull(realPrice) Then DisplayPrice(realPrice)

Under .NET a Null database field returns a DBNull object – more precisely, the DBNull.Value element. The problem is, no math or string operation is defined for the DBNull type, something I consider one of the most serious mistakes Microsoft made in this area. As a result, the third statement throws an exception if either field is Null. So long, functional equivalence! Welcome, migration head-aches!

Null propagation is a serious problem not to be underestimated. One of our customers has found that, on the average, one out of 40 statements uses Variant expression and relies on null propagation. To put things in the right perspective, in a middle-sized real-world application you can expect to manually fix several thousand statements that use null propagation. What’s worse, there is no simple way to work around Null values in VB.NET, short of splitting all statements in portion and testing each and every subexpression for the DBNull.Value value.

If you use VB Migration Partner, you can solve the above problem in the most elegant and painless way. Just use the following project-level pragmas:

 '## project:NullSupport
 '## project:ChangeType Variant, VB6Variant

The NullSupport pragma tells VB Migration Partner to map some VB library functions – such as Left, Mid, Right, and a few others – to special methods that are defined in VB Migration Partner’s support library and that, not surprisingly, correctly return a Null value if their argument is Null (as they do under VB6).

The ChangeType pragma converts all Variant members – variable, fields, properties, methods, etc. – as the special VB6Variant type (also defined in VB Migration Partner’s support library) which redefines all the math, comparison, string, and logical operators to support null values.

Yes, this is all you need to add null propagation support to your VB.NET code! This feature alone can save you literally weeks in a real-world migration project. And don’t forget that VB Migration Partner is the only VB6 conversion software that supports Null values and Null propagation easily and automatically.

When you hear other vendors claiming that “our tool uses advanced artificial-intelligence-based techniques to ensure functional equivalence with the original VB6 code”, just ask them how it deals with Null values. Smile