English 中文(简体)
Utility to Convert Legacy VB6 Function Calls to .NET [closed]
原标题:

I am looking for a utility/tool to convert calls to legacy VB6 functions to the .NET equivalent.

For example, it would convert this...

FormatCurrency(Cart.TotalAmount)
Len(Str)
UCase(Str)
UBound(PaymentsArray)

To this...

Cart.TotalAmount.ToString("c")
Str.Length
Str.ToUpper()
PaymentsArray.Length - 1

Does anybody know of one, or am I going to have to roll my own?

问题回答

Do you need a conversion for those functions? The vb6 functions work just fine in vb.net.

If your code is already converted to working VB.Net, why not just leave the calls as they are? The routines are in Microsoft.VisualBasic.dll which is a fully supported part of the .NET framework and will be around as long as .NET is around. Avoid using them in new code if you like, but doing extra work to take them out of existing code seems rather unecessary.

If you haven t yet converted the code, you could choose to buy Artinsoft s VB Upgrade Companion which can do some of the conversions you ask for, as part of the VB6 to VB.Net conversion.

With gmStudio, the VB6/ASP/COM analysis and re-engineering tool from Great Migrations, you can control these things by changing the surface forms used by the string machine as it interprets the pcode generated by its compiler and authors it in the desired notation. For example, here are the default surface forms for Len:

  <subcode id="Len">
     <vbn role="function" narg="1" code="Strings.Len(%1d)"/>
     <csh role="function" narg="1" code="VBNET.Strings.Len(%1d)"/>
  </subcode>

To customize the C# code emitted for the Len operation you can apply an override and create a custom translation configuration:

  <subcode id="Len">
     <csh role="function" narg="1" code="%1d.Length"/>
  </subcode>

The placeholder %1d indicates where the original parameter should be emitted into the C# code stream.

This is a simplification of a very simple case, but that s the idea.

NOTE: the default surface forms are closer to the original semantics of VB6. For example string.Length throws an exception in C# if the argument is null, but VBNET.Strings.Len() returns 0. That said, if you never expect a null string then throwing an exception when one occurs might be advantageous -- or not -- at least you have the choice.

There is a free migration tool from Microsoft available here. It was released when VS2003 was released.

You get it here: http://blogs.msdn.com/b/bethmassi/archive/2010/07/08/free-vb6-migration-tool-amp-updated-vb-developer-center.aspx





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签