Looking for advice on coding standards to aid move from VB6 to C# .Net

My team has been supporting systems that use VB6, Access and MSSQL for years. The plans to move to C#, .Net and MsSql have been put on hold for another year. I am looking for advice on coding standards that would reduce the amount of rewrite required when we actually begin the transition. This includes our existing code base (enhance to transition) and anything new we add during the next 12 months using VB6.

Who is Participating?
OrcbighterConnect With a Mentor Commented:
Having been through a number of such conversions, the last being to convert VB6 code to VB.Net code, I can tell you it a big task with many traps.

The first point to make is that VB6 C# completely different languages. This may seem like a statement of the bleedin' obvious, but it is important to remember that VB6 is unmanaged code while C# is managed code.

From my experience a great deal of VB6 code is badly written and badly designed, with whole functions controlled by a line at the start of the function "on error goto" acting like a huge try-catch block that does not guarantee resource cleanup. Functions that have multiple exits from them without cleaning up resources (something you can get away with in unmanaged code when your variables are declared on the stack, but not in managed code when your variables are declared on the heap).

Another point to remember is that, if your code makes calls out to unmanaged DLLs, you will have to take extra care of Marshalling the resources passed back and forth, and also will have to look out for resource leaks around the use of pinvoke.

Your first decision - to use C# instead of VB.net is a very good one.
Your second decision should be, if you have been given the time, is to examine the old code and see if you really need to copy/convert what is there. For example some complex code may be replaced by a call to an existing class/method supplied in the framework - replace ten lines of code with a single api call. C# is a more powerful and elegant language than VB6. Maybe the existing code could be written in a better way.

Anyway, I have written an article on converting a VB6 project to VB.Net. Apart from the point about buffer allocation, all the points raised apply equally to C#.
It is not a big article so give it a read. It will highlight some of the problems you might face.

anjosConnect With a Mentor Commented:
We used Instant C# (http://tangiblesoftwaresolutions.com/) to convert our whole application to C# and then went through the process of checking and fixing all errors that appeared during compilation and it worked out pretty well.
MajorBigDealConnect With a Mentor Commented:
Eliminate use of "With"and make explicit.

Find all default properties and make them explicit.   For example,  you might be setting Captions on a Label without actually specifying Caption.

Change your select case statements to use constants.  If you are doing calls or evaluations in your cases, evaluate them first before entering the select, or else change it to an "if then else".  C# doesn't like calls and evaluations in switch case statements

Well, that is a few items, I think someone could write a whole book on this. Depending on how familiar you are with C#, you might want to consider converting to VB.NET first, getting your systems up and running in .net and then you can take your time getting them converted from VB.NET to C#.  Of course, if you already have the C# skills, this would just be extra work but if you are not proficient in C# it might be an easier (less stressful) transition path.
tkusistoAuthor Commented:
Thank you all for your comments. Forearmed I feel more confident.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.