A VB6 programmer that is looking for some information to help them through this process is much more likely to search by 'Upgrade' rather than 'Port', because they will be thinking 'Upgrade from VB6 to VB.NET', thanks to Microsoft. Even the wizard is called an 'Upgrade Wizard' instead of 'Port Wizard'. As far as C# verses VB.NET. Jump to What is the VB.NET equivalent for Visual Basic 6.0 WebClass projects. In Visual Basic 6.0, WebClass projects (also known as.
I'm currently working for a company where I have to upgrade over 50 VB6 programs to VB.NET 2008. So far I'm about half way through, and I've learned quite a few tricks that drastically improve the performance of VB.NET apps.
Because there are a lot of programmers that are going to be making this move, I thought I would share this information. I'm certain it will be very valuable to those who are faced with this task. One of the first things to think about is whether you want to upgrade your VB6 program to a VB.NET 2008 Windows Forms application or a VB.NET 2008 Windows Presentation Foundation (WPF) application. If you are upgrading to VB.NET 2005, then you don't have the WPF option, but if you are upgrading to VB.NET 2008, then you do, and you may choose to use it. Why would you want to upgrade a VB6 Windows Forms application to WPF? Because that is the future of Windows programming. Windows Forms have been using the same technology for more than 15 years, and are now at the very beginning of their sunset. Windows Forms applications use User32 (User before 32-bit) and GDI/GDI+ for gui rendering, but WPF applications use DirectX for gui rendering, which is much more powerful. Additionally, WPF uses Extensible Application Markup Language (XAML) to define the layout of the interface, and instantiate .NET objects. By far, the easiest choice is to upgrade a VB6 Windows Forms application to a VB.NET 2008 Windows Forms application. Since Windows Forms are going to be around for quite a while, we'll take a look at that. Here are some steps and tips for upgrading a VB6 Windows Forms application to a VB.NET 2008 Windows Forms Application: Use VS 2008's Upgrade Wizard Change the Target Framework Delete the Upgrade Report Correct all errors Update Code Add API's to increase DoEvents performance. 1. Using the Visual Studio 2008 Upgrade WizardOpen Visual Studio 2008 From the File menu, select Open | Project/Solution - Navigate to the VB6 project that you want to upgrade, and select it. - The Upgrade Wizard will start automatically. - Click 'Next' through each window of the Wizard until the Wizard begins the conversion. ** Upgrade Errors: I have encountered some VB6 projects that did not complete the Upgrade Wizard, and would not upgrade. A couple of the errors I received were: 'Upgrade failed: General error accessing file 'C' and 'Unable to read the project file...' If you have a problem upgrading a VB6 application to VB.NET, then you have 3 options: 1. Install Visual Studio 2008 Service Pack 1 (SP1) and try it again. 2. Use the command-line version of the Wizard. This is the same Upgrade engine that is used by the VS IDE Upgrade Wizard, but for some reason it worked every time a VB6 program crashed during upgrade. Here's how: - Create a folder on the C: with a short name (like 'Upgrade') - Copy and paste the VB6 Project files into this folder. - Open a Visual Studio Command Prompt (Windows XP: Start button > All Programs > Microsoft Visual Studio 2008 > Visual Studio Tools > Visual Studio 2008 Command Prompt) - Make sure you are in the VB directory (mine opened to VC) - Type 'cd..', press Enter to move up 1 directory. - Type 'cd VB', press Enter to change directory. - Go to the VBUpgrade directory - Type 'cd VBUpgrade', press Enter. - Run the command-line version of the Upgrade Wizard: - Include 'VBUpgrade.exe' - Include the input project path <filename> - Include the new folder the VB.NET project will be created in (Output directory) Structure: VBUpgrade.exe <filename> /Out <directory> Example: VBUpgrade.exe 'C:UpgradeProject1.vbp' /Out 'C:UpgradeVB Upgrade' - Press the Enter key after you type the above, and the Upgrade should begin. 3. If the command-line version of the Upgrade Wizard does not work for you, try contacting John Hart at Microsoft ([email protected]), he may be able to help. 2. Change the Target FrameworkBy default the Target Framework will be set to '.Net Framework 2.0'. You can use this if you want to. I changed it to '.Net Framework 3.5'. If you desire to do so, here's how: - Click on the Project Menu | Properties - Click the Compile tab - Click the 'Advanced Compile Options...' button at the bottom of the tab page - Change the 'Target framework' to '.Net Framework 3.5' - Click 'OK', then 'Yes' 3. Delete the Upgrade ReportWhen you perform an Upgrade using the Upgrade Wizard, an Upgrade Report is automatically generated. If you would like to look at the report, then Open the Solution Explorer in Visual Studio (View menu | Solution Explorer), and double-click '_UpgradeReport.htm'. I personally haven't used the report, so I delete it (right-click, Delete in Solution Explorer). - If you decide to delete the report, you'll also need to open Windows Explorer and navigate to your project folder, then delete the '_UpgradeReport_Files' folder. Example: delete 'C:UpgradeVB Upgrade_UpgradeReport_Files' 4. Error CorrectionOnce you upgrade your VB6 Windows Forms application to .NET, you will have lots of errors! To see a list of errors, open the 'Error List' (View menu | Error List). To actually go to an error, double-click an error from the Error List. Visual Studio will automatically take you to the line of code where the error occurs. Above the line of code where the error occurs, you will notice an 'Upgrade Warning'. This warning describes the error, and provides a fairly helpful link that can help you get more information about the error, plus steps you can take to fix the error. To use the link, hold down the control button and left- click it with your mouse. For example, if you had a CommonDialog control on your VB6 form, then you will receive an error informing you that the CommonDialog was not upgraded. The helpful link will provide links to new controls that replace the CommonDialog, such as 'OpenFileDialog', 'SaveFileDialog', etc. Correct all of the errors in the project before continuing. 5. Update CodeVB.Net 2008 continues to support many VB6 methods. HOWEVER, they are actually SLOWER than their VB.NET counterparts, so it is very important to go through each line of code in your project, and replace each VB6 method with it's .NET counterpart. VB6 code runs good in VB6, but VB6 code in VB.NET runs bad (very bad). VB.NET code in VB.NET runs good (VERY good), much faster than VB6 code runs in VB6 (if that makes sense). So here are some examples of how to replace VB6 methods with VB.NET counterparts: 'TIP: VB.Net strings are zero based, in other words, the first position of a string is 0. In VB6, the first position was 1. This greatly affects how strings are parsed. Dim myString As String = 'Go ahead and search for this string' - Instr - Instead of using the Instr() method to search a string, use the IndexOf() method. Old way: Instr(myString, 'search for this string') New way: myString.IndexOf('search for this string') - Mid - Instead of using the Mid() method to get a portion of a string, use the SubString() method. Old way: Mid(myString, 14) New way: myString.SubString(13) - Trim - Instead of using the Trim(), LTrim() and RTrim(), use .Trim(), .TrimStart(), .TrimEnd() Old way: Trim(myString), LTrim(myString), RTrim(myString) New way: myString.Trim(), myString.TrimStart(), mystring.TrimEnd() - Len - Instead of using the Len() method, use .Length() to get the length of a string. Old way: Len(myString) New way: myString.Length() - Replace the 'And' operator with 'AndAlso', replace the 'Or' operator with 'OrElse'. Do this in any non-bitwise comparison. And Old way: If 1 = 1 And 2 = 2 And 3 = 3 Then And New way: If 1 = 1 AndAlso 2 = 2 AndAlso 3 = 3 Then Or Old way: If 1 = 1 Or 2 = 2 Or 3 = 3 Then Or New way: If 1 = 1 OrElse 2 = 2 OrElse 3 = 3 Then - Replace ALL VB6 File I/O classes with the new .NET File I/O Classes. They are faster than VB6's so make sure you use them! Dim myFile As String = 'C:Tempmyfile.txt' Dim instring As String = String.Empty ** VB6 File I/O: FileOpen(1, myFile, OpenMode.Input) Do Unil EOF(1) instring = LineInput(1) 'Read 1 line from a file Loop FileClose(1) ** VB.Net File I/O: Dim reader As New System.IO.StreamReader(myFile) Do Until reader.EndOfStream = True instring = reader.ReadLine() Loop reader.Close() reader.Dispose() 6. DoEventsAs soon as I upgraded processor intensive VB6 applications to VB.NET, I noticed that the performance was terrible! While code upgrades are contributing factors, DoEvents is one of the biggest culprits! VB6 applications ran (in some cases) about 10 times slower when they were upgraded to VB.NET. With a few tweaks, VB.NET application performance can be greatly improved, so that they run about 40% - 50% FASTER than VB6... 1. Add a Module to your project, and name it something like 'Do_Events' 2. Insert the following code into the module you added: Module Do_Events Friend Declare Function SetThreadPriority Lib 'kernel32' (ByVal hThread As Integer, _ ByVal nPriority As Integer) As Integer Friend Declare Function SetPriorityClass Lib 'kernel32' (ByVal hProcess As Integer, _ ByVal dwPriorityClass As Integer) As Integer Friend Declare Function GetCurrentThread Lib 'kernel32' () As Integer Friend Declare Function GetCurrentProcess Lib 'kernel32' () As Integer Friend Const THREAD_PRIORITY_HIGHEST As Short = 2 Friend Const HIGH_PRIORITY_CLASS As Integer = &H80 End Module 3. Add 2 lines of code before the intensive processing begins to set the thread priority: SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_HIGHEST) SetPriorityClass(GetCurrentProcess, HIGH_PRIORITY_CLASS) 4. Use DoEvents() sparingly! Calling DoEvents() has a big performance hit, so use it sparingly. Dim iLoops As Integer = 0 Do Until iLoops = 10000 'Calling DoEvents() every 500 loops will greatly increase application performance If iLoops Mod 500 = 0 Then DoEvents() iLoops += 1 'Add 1 to iLoops Loop 5. Create a specific Sub routine for updating the controls on your Form, and call the Sub whenever you want to update the form. In the example above, you can substitue DoEvents() with the name of your update method Example: Private Sub UpdateForm() 'Update all controls here: progressBar1.Value += 1 'Update ProgressBar label1.Text = 'Processing...' 'Update Labels, TextBoxes, etc... Application.DoEvents() 'Call DoEvents() so the form can refresh the changes to the controls End Sub If you follow the steps and tips included in this article, then your upgrade should go pretty smoothly, and your application should perform quite a bit faster in VB.NET than it did in VB6. Good luck! VBRocks
Today I’m pleased to announce the re-launch of our VBRun developer center for VB6 developers and a free partner tool offer. If you haven’t been there before VBRun is all about providing the best migration strategies, tools, support info, and training to help you on your gradual path from VB6 to .NET. The biggest addition to the new developer center is the featuring of a partner page that provides free and recommended tools (details about this below). We’ve also taken steps to bring the VBRun and VBasic developer centers closer together – starting by adding the VB6.0 tab (links to VBRun) right off of the VBasic developer center.
The first partner to be featured on the new VBRun is Artinsoft with their Visual Basic Upgrade Companion [VBUC] tool. We have worked together to bring you a completely FREE version of the enterprise-strength Artinsoft VBUC tool that supports up to 10,000 lines of code conversion per solution (you can purchase higher editions of the product to convert more lines of code). You can think of VBUC as being the evolution of the former VB Upgrade Wizard that shipped in Visual Studio 2008 and earlier. In many ways it is a true evolution of the code Artinsoft helped us with circa 2002.
There are several improvements with the VBUC tool:
- Drastic reduction in errors, warnings, and bugs caused by the tool’s inability to understand and upgrade your code. The goal was to get much closer to full functional equivalence to your VB6 code so you can instead focus on innovating on your .NET code as appropriate to your business. Of course no migration tool will be able to migrate 100% of your code without some work and testing on your side, but this tool will help you minimize the tedious effort and gotchas so you get very close.
- Support for VS2010 and 9 languages – just as you’d expect we have added full support for the best version of Visual Studio yet – VS2010. Additionally we thought it would be important to enable the VBUC tool in the same locales as the version of Visual Studio you’re using. The version of VBUC you can get to today supports English, Japanese, and German. In a few weeks we plan to publish an update to add support for Chinese Simplified and Traditional, French, Spanish, Italian, and Korean languages.
- Support for conversion to VB.NET and C# - you can choose the language that best fits the skills of your team.
- Deep configuration of code conversion rules. Artinsoft embraces the iterative nature of migration and they provide way to customize code conversion rules. To modify these you want to check out the Profile Manager in the tool.
- Better handling for late bound code. We’re all either smart or guilty for using late bound code depending on how you look at it. Unlike previous tools this version can detect late binding and automatically fix conversion issues and generic types that do not behave well in .NET.
- Assessment features – in the past you’d have you download the Patterns and Practices assessment tool or work with consultants to figure out how much work lays in front of you in a migration. VBUC includes a built-in assessment tool that will create configurable reports about your code, dependencies, difficult controls/code, etc. so you can better estimate your costs and risks. To run the assessment tool just hit F4 in the tool. A cool side thing is the results are reported in HTML pages and Excel spreadsheets so it’s easy to read and tweak for your own report.
Check out this VBUC download landing page for more details about what you can do with this tool (remember to type in the code MSDN to get the $799 version for free).
We expect to continue posting our best migration strategies, best new partner tools, support policies, updated version of Interop Forms Toolkit 2.1 (adding .NET forms and user controls to VB6 apps), and guidance on the VBRun site so you should check back often. There is also a lively VB6 migration and interop forum where experts on my team and expert MVPs hang out.
If you’re facing VB6 migration challenges, I hope you check out this site and find the tools will be of use to you.
Enjoy!
[Edit: fixed image URL's]
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |