Conversion of a Visual Basic 6 Application to Visual Basic .NET
Total Page:16
File Type:pdf, Size:1020Kb
FAK EKI Margaret Mburu and Robert Josefson Conversion of a Visual Basic 6 Application to Visual Basic .NET Subject C-level thesis Date/Term: 08-06-03 Supervisor: Donald F. Ross Examiner: Martin Blom Serial Number: C2008:06 Karlstads universitet 651 88 Karlstad Tfn 054-700 10 00 Fax 054-700 14 60 [email protected] www.kau.se Conversion of a Visual Basic 6 Application to Visual Basic .NET Margaret Mburu and Robert Josefson ii This report is submitted in partial fulfillment of the requirements for the Bachelor’s degree in Computer Science. All material in this report which is not our own work has been identified and no material is included for which a degree has previously been conferred. Approved 080603 Advisor: Donald F. Ross Examiner: Martin Blom iii Abstract This dissertation describes the process of converting an application from Visual Basic to a .NET programming language. This work was carried out on behalf of The Prevas Company [0] based in Karlstad, Sweden. Prevas provides IT solutions and industrial systems for several world leading companies such as Ericsson, Nokia, Siemens and many others. The objective behind the conversion of this application was to facilitate a more compatible and flexible option suitable for the other products using the .NET environment. In addition, Prevas felt that the Visual Basic 6 environment had grown rather old and outdated. The task was therefore to convert the source code from Visual basic 6 to .NET language and to determine the most efficient method for the conversion. The outcome of this project was to achieve a fully converted application using the .NET framework with its original functionality intact. iv Contents 1 Introduction ...................................................................................................................1 1.1 Document Outline ..................................................................................................2 2 Background ....................................................................................................................3 2.1 Visual Basic 6.0 ......................................................................................................3 2.2 Visual Basic 6.0 Features ........................................................................................3 2.3 .NET Framework ....................................................................................................4 2.3.1 Common Language Runtime 2.3.2 Compilation 2.3.3 .NET Framework - Class Library 2.3.4 Other .NET Related Languages 2.3.5 C# (SHARP) 2.4 Differences between Visual Basic 6 and Visual Basic.NET ....................................7 2.4.1 Multithreading 2.4.2 Object Oriented Feature 2.4.3 Console Applications 2.4.4 Memory Management 2.4.5 Runtime Environment 2.4.6 Data Types and Properties 2.4.7 Declaration and Initialization of Variables 2.4.8 Structures and User – Defined Types 2.4.9 Arrays 2.4.10 Fixed Length Strings 2.4.11 Structured Exception Handling 2.4.12 Compatibility 2.4.13 Security 2.4.14 Forms 3 Conversion Process ...................................................................................................... 15 3.1 Language Decision: .............................................................................................. 16 3.2 Before the Conversion .......................................................................................... 16 3.3 Results .................................................................................................................. 17 3.4 Compile Errors ..................................................................................................... 17 3.4.1 Property was not Upgraded (Compile error). 3.4.2 Declaring a parameter 'As Any' is not supported 3.4.3 Unable to determine which constant to upgrade vbNormal to 3.4.4 Number of Indices Exceeds the Number of Dimensions of the Indexed Array 3.4.5 Other Possible Compile Errors v 3.5 Upgrade Warnings: ............................................................................................... 26 3.5.1 Event may Fire when Form is initialized 3.5.2 Structure may require Marshalling Attributes to be passed as an Argument in this Declare Statement. 3.5.3 The Lower Bounds of a Collection has Changed 3.5.4 Other Possible Upgrade Warnings 3.5.5 Could not Resolve Default Property 3.6 Design Errors ....................................................................................................... 32 3.6.1 Property not Upgraded (Design error) 3.6.2 Other Possible Design Errors 3.7 Changing caching from string to XML ................................................................. 35 3.7.1 XML (Extensible Markup Language) 3.8 Issues Discovered During Testing ......................................................................... 37 3.8.1 VB.NET Registry Changes 3.9 Upgrade Summary ................................................................................................ 42 4 Results .......................................................................................................................... 44 4.1 Upgrade Checklist ................................................................................................ 44 4.1.1 Checklist 4.1.2 Before the Upgrade (Checklist: steps 1 and 2) 4.1.3 Application Version 2 (Checklist: step 3) 4.1.4 Test of application version 2 (Checklist: step 5) 4.1.5 Test of Application Version 3 (Checklist: steps 6, 7 and 8) 4.2 Project Overview .................................................................................................. 48 4.2.1 Knowledge 4.2.2 Software Tools 4.2.3 Planning 4.2.4 Project Summary 4.3 Project Evaluation ................................................................................................ 49 4.3.1 What was learned 4.3.2 Evaluation 5 Future Conversions ..................................................................................................... 51 5.1 Approach .............................................................................................................. 51 5.1.1 Partial Upgrade 5.1.2 Complete Upgrade 5.1.3 Complete Re-write 5.2 Preparations .......................................................................................................... 52 5.3 Changes ................................................................................................................ 53 5.3.1 Fixing Data Declaration 5.3.2 Obsolete Keywords 5.4 Tools .................................................................................................................... 54 5.4.1 Migration Cost Estimation Tool 5.4.2 Project analyzer and Compatibility Check Tool 5.5 Conclusions .......................................................................................................... 55 References ........................................................................................................................... 56 A Glossary ....................................................................................................................... 59 vi List of Figures Figure 2-1 The Common Language Runtime Environment[2] ........................................5 Figure 2-2 The Common Language Infrastructure[2] .......................................................6 Figure 2-3 Example Win32 Application in VB.NET ........................................................9 Figure 2-4 Example of Variant Data Type ..................................................................... 10 Figure 2-5 Variable declaration example ........................................................................ 11 Figure 2-6 Initialization and declaration in VB.NET ...................................................... 11 Figure 2-7 VB6 Structure ............................................................................................... 12 Figure 2-8 VB.NET Structure ........................................................................................ 12 Figure 2-9 VB.NET Array ............................................................................................. 13 Figure 3-1 WinHelp function ......................................................................................... 18 Figure 3-2 App.PrevInstance replacement ...................................................................... 19 Figure 3-3 The GetPrivateProfileString Function Declaration ........................................ 20 Figure 3-4 Example function with SQL Attributes ......................................................... 21 Figure 3-5 Example of Code with the vbNormal Constant ............................................. 22 Figure 3-6 Declaration of a multidimensional array ....................................................... 24 Figure 3-7 Life cycle of OLE VB6 drag and drop operation ........................................... 25 Figure 3-8 Subroutine not using IsInitializing ................................................................ 28 Figure 3-9 Subroutine using IsInitializing ...................................................................... 28 Figure 3-10 VB6 code without marshalling .................................................................... 29 Figure 3-11 Visual Basic .NET Code with Marshalling .................................................. 29 Figure 3-12 Modified code ............................................................................................ 29 Figure 3-13 Array Declaration ....................................................................................... 29 Figure 3-14 Imagelist ....................................................................................................