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.

tkusistoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

anjosCommented:
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.
0
MajorBigDealCommented:
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.
0
OrcbighterCommented:
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.

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/A_3883-Converting-VB6-to-VB-NET.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tkusistoAuthor Commented:
Thank you all for your comments. Forearmed I feel more confident.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.