How can I convert VB6 code to C#? [closed]

2020-01-30 08:30发布

Does anyone know a way to convert from VB6 code to C#?

Is there a tool that can do this for me?

10条回答
别忘想泡老子
2楼-- · 2020-01-30 08:44

Artinsoft (Now renamed to Mobilize.Net) does just this, especifically the Visual Basic Upgrade Companion.

However, even after using the VBUC there's still some parts that of the system that needs to be migrated/proofed by hand. But it's usually a much smaller set of the original problem. And some of the migration issues have been resolved thanks to experience with past migrations.

Artinsoft is the same company that built the wizard that ships with Visual Studio, mentioned in theraccoonbear's post. However, if I'm not mistake the wizard only migrates VB6 to VB.Net.

Full disclosure: I work for Artinsoft

查看更多
别忘想泡老子
3楼-- · 2020-01-30 08:46

VisualStudio offers (or at least offered) a wizard to do a conversion from VB6 to VB.NET (which could then be converted to C# with a bit of work, possibly helped by #develop's VB.NET <-> C# converter), but when last I used it, for anything non-trivial there was a lot of manual work needing to be done so I suspect you're probably better rewriting or porting by hand if this is a large and/or important application.

查看更多
对你真心纯属浪费
4楼-- · 2020-01-30 08:47

Open your project with a new version of Visual Studio, convert your code to VB.Net and then download .Net Reflector to help you with the C# transformation.

Good luck!

查看更多
神经病院院长
5楼-- · 2020-01-30 08:50

One question to ask yourself is, how important is it to have C# rather than VB.NET? If you're converting a large application, perhaps you should just upgrade to VB.NET, which will be cheaper.

There are some features in VB6 with no exact equivalent in C# (the error handling, late binding etc). Ask yourself why it's worth the manual effort to convert those, when you could go to VB.NET which does support them.

And if you don't believe me (and no-one's voted for my answer, sob sob!) maybe you'll believe Francesco Balena and Dan Appleman (in a book Moving to VB.NET) who agree with me.

查看更多
家丑人穷心不美
6楼-- · 2020-01-30 08:52

It might come across as a little bit cheeky but your brain might be the best tool to use. Could be worth the re-write.

Maybe you don't need to porting it. Could the VB6 be turned into a COM component? Port to COM, call from C#, home in time for Judge Judy.

查看更多
看我几分像从前
7楼-- · 2020-01-30 08:52

As someone who has done this a bunch of times, this is not an easy process. You can use the VB6 to VB.Net tool as stated in this answer, and then use either Reflector or SharpDevelop to convert to C#. With the SharpDevelop conversion, a few caveats. It screws up all the array references and thinks that they are function calls, and all the logical operators are converted to bitwise logical operators (And becomes & not &&). With Reflector you lose a bunch of stuff. Also the Visual Studio converter fails on a lot of large projects, just hangs and never completes.

Once you have got your code converted into C#, you have to start the real work. The conversion gets you at best 50% of the way there, you have to fix a ton of stuff (you will see your code littered with TODO's), refactor a ton of stuff, and at the end you are left with C# that is a representation of your VB6 -- unless you have very nice VB6 code not a place you really want to be. Also all of your code with be littered with the VB helpers rather than using proper DotNet functions (all the string functions are helpers rather than class objects, for examples0. If you used Variants at all those all have to be rewritten. If you used a lot of API calls, they tend to need rewritting.

In the end you will get a base, but converting a large project (20-30 forms, 30 classes, 30 modules) can take several man months. Rewritting from scratch, however, may take twice as long and you lose all of your business logic. So, it can be done (I have done it with 3 or 4 large projects), but there is no panacea, no silver bullet, and any tool that says it will do it for you alone, is lying.

查看更多
登录 后发表回答