Welcome!

Microsoft Cloud Authors: Janakiram MSV, Yeshim Deniz, David H Deans, Andreas Grabner, Stackify Blog

Related Topics: Microsoft Cloud

Microsoft Cloud: Article

Converting VB6 to VB.NET, part 3

Easy transition, positive results

This is the third and final installment in a three-part series. In the first installment (.NETDJ, Vol. 2, issue 9), I covered general conversion issues, in the second installment (Vol. 2, issue 10), I finished general conversion issues, and covered issues associated with database conversions. In this final installment, I will cover ASP Web page conversions, converting to VB.Net 2005, converting to C#, and finally, I will cover some arguments for converting.

Converting ASP to ASP.NET
Converting from ASP to ASP.NET is probably the easiest of all .NET conversions because ASP Web pages can be used side-by-side with ASP.NET Web pages, meaning the conversion can be done on a page-by-page basis. This is because the ASP and ASP.NET engines, like many things in .NET, can run side-by-side. The server knows which engine to pass the page to because ASP pages have a .asp extension, and ASP.NET pages have a .aspx extension.

One exception to this is that ASP pages and ASP.NET pages are considered different applications in different sessions, so session variables and other session and application states cannot be shared. There are two solutions to this problem. The first is to convert all pages that share state information to ASP.NET as a group. The other option is to use a different method to share the information, such as a database, or the data can also be posted from one page to another, regardless of whether the pages are written in ASP or ASP.NET. Details on how to share states using databases can be found at http://msdn.microsoft.com/asp.net/using/migrating/ default.aspx?pull=/library/en-us/dnaspp/html/converttoaspnet.asp.

Another issue that complicates conversions is that while a single ASP page can use more than one server-side scripting language, each ASP.NET page is limited to a single server-side scripting language. Allowing mixed scripting languages was required with ASP because of limitations with scripting languages such as incomplete support for COM objects in JScript; this occasionally required adding VBScript to pages that otherwise would have been written completely in JScript. In ASP.NET, these limitations in JScript have been removed, making mixed scripting languages unnecessary in most cases. This should make JScripters happy, but it may generate extra work during the conversion process. Because client-side script, even that generated by server-side script, is executed on the client, it doesn't need support from ASP.NET and so is still allowed in ASP.NET.

Because ASP and ASP.NET pages can coexist, the simplest conversion strategy is to just start writing new pages in ASP.NET.

The next step is to just change the extension of a page from .asp to .aspx; because ASP.NET was designed to be compatible with ASP, simple ASP pages may run as ASP.NET pages without change.

Because ASP scripts are interpreted, and ASP.NET scripts are compiled, any scripts used by the page will typically run much faster without any other changes.

Doing the ASP Conversion
ArtinSoft, the company that wrote the VB6 to VB.NET converter for Microsoft, has also written an ASP to ASP.NET converter for Microsoft that can be downloaded from www.asp.net/MigrationAssistants/Default.aspx?tabindex=0&tabid=1 . Downloadable from the same page is a PHP to ASP.NET converter, and information on using the Java Language Conversion Assistant (JLCA) to convert JSP pages to ASP.NET pages; they also have a PL/SQL (Oracle) to T-SQL (Microsoft) database conversion assistant that can also be downloaded from their Web site. Their home page is at www.artinsoft.com; from their download link, you can get access to more help on the assistants, and several useful white papers. ArtinSoft is one of several companies that will also do the complete migration for you, or consult in specific migration issues for a price.

Converting from ASP to ASP.NET can be broken down into three parts, converting old scripts to the new scripting languages, addressing new limitations in ASP.NET, and taking advantage of new .NET features.

JScript.NET is backwards compatible with JScript, so JScript scripts can be used with ASP.NET without modification; however, JScript.NET has a number of enhancements such as namespaces, enumerations, constants, conditional compilation, and typed variables that can be taken advantage of; other .NET languages can also use JScript.NET objects.

There is no VBScript.NET; .NET uses full-blown VB.NET, so VBScript will need to be converted to VB.NET. This is similar to converting VB6 to VB.NET and using the ASP.NET conversion assistant to convert VBScript is similar to using the VB upgrade assistant to convert from VB6 to VB.NET. Most of the information in the first two parts of this article will apply here; the main difference is that some changes I recommend making before the conversion, such as declaring all variables and giving them explicit types, are not valid in VBScript and must be made after the conversion.

As with the VB6 conversion, parts of the ASP pages that the assistant cannot convert will be marked for manual conversion, and a conversion report listing unresolved issues will be attached to the project.

Because VB.NET has so many advances over VBScript, such as supporting objects and inheritance, once the conversion is made there will be lots of opportunities for improving the code. As with JScript, VB.NET is compiled and able to interoperate with other .NET languages.

In addition to changes in scripting, many ASP pages will need some changes to become ASP.NET pages; the conversion assistant will make most of these changes.

One simple change is that since the extension for converted pages changes from .asp to .aspx, references to other pages from within a page will require the extension on the reference to also be changed.

ASP, like VB6, does not require variables used by a page to be declared or typed, but ASP.NET does. The assistant adds declarations for undeclared variables, and when it does, the assistant also examines how untyped variables are used in the code, and tries to declare the variable as the correct type.

ASP.NET has different limitations from ASP on what type of code can appear within the bounds of which tag type. The conversion assistant will move code around and add tags as needed to match the new ASP.NET rules. It will also move variable declarations around to match new rules about how variables are scoped. An example of this is that in ASP subroutines, variables can be declared in render tags (<% %>), but in ASP.NET, they must be declared in script tags (<script> </script>). There are also other changes the assistant will make to reflect changes in tag syntax between ASP and ASP.NET.

With the sweeping changes between ASP and ASP.NET, it is not surprising that there are some major parts of a Web application that the conversion assistant cannot convert. For instance, the assistant can convert simple rendering functions, but it is unable to convert many of the more complex rendering functions. It will however, mark the code for manual conversion. Also, as mentioned above, any ASP page that uses multiple server-side scripting languages will need to be modified either before or after conversion to use a single scripting language; this will likely require converting some scripts to a different language. Later in this article I will cover some tools that can help convert between some .NET languages.

Possibly the most difficult part of the ASP to ASP.NET conversion will be security issues. In ASP, security was provided by IIS impersonating the user accessing the page. ASP.NET has much richer security options, giving the designer far more control. Covering security issues is beyond the scope of this article, but a nice overview of ASP.NET security can be found at www.asp101.com/articles/cynthia/authentication/default.asp, and more details can be found in the links on http://msdn.microsoft.com/library/default.asp?url=/ library/en-us/vbcon/html/vboriSecurityForASPNETWebApplications.asp.

One advantage to converting to ASP.NET is the addition of new controls and control types. In addition to the HTML controls available in ASP, ASP.NET adds ASP.NET validation and user controls.

ASP.NET controls have several advantages over HTML controls. The first advantage is that ASP.NET controls can dynamically generate either HTML or JScript code that is compatible with the user's browser, for an example of this, see www.developerfusion.com/show/2074/3/. Another advantage of ASP.NET controls is that they can be bound to data similar to the way Winform controls can be bound to data. The controls properties can be bound to variables, properties of other controls, collections, or data sources including XML recordsets.

Validation controls do exactly what their name implies; they are attached to input controls and validate data entered into the controls. They support most common validation scenarios, including ranges and patterns, they can verify that required fields are filled out, as well as executing custom validation logic written by the Web developer. Details on what validations are supported can be found at http://msdn.microsoft.com/library/default.asp?url=/ library/en-us/vbcon/html/vbcontypesofvalidation.asp.

User controls allow even beginning Web developers to create new controls aggregated from other controls. An example of such a control would be a login control that combined a pair of labels ("User Name" and "Password") with a pair of textboxes, and related validation code. These would all be combined into a single control that could easily be dropped into multiple Web sites.

Does this example make you wonder why Microsoft did not include a login control as one of the standard ASP.NET controls? Well they did, it just took them until version 2.0 to do it! As big a leap forward as ASP.NET is, ASP.NET 2.0 is an even bigger leap, and the poster boy for version 2.0 is the new login control. Everyone who has seen the new .NET 2005 login control loves it. This control includes all login related code including the login control itself, authentication, adding new users, and handling the database holding login information (including adding new members to the database). It is simply amazing how much this control handles, how well it handles it.

ASP.NET 2.0 also has even more security features than the current version. Zak Ruvalcaba has a nice Web page devoted to ASP.NET 2.0 security, including the login control, at www.sitepoint.com/article/asp-net-2-security; also, a link off that page allows you to download four sample chapters of his book on ASP.NET 1.0.

Another great ASP.NET 2.0 feature is the ability to use master Web pages; these are like base classes for programmers. You can, for instance, create a standard master Web page with headers, logos, and custom navigation panes, and then use that page as the base for all of your other pages, giving them all the same look and feel. Unlike ASP, you can then change the derived pages without the changes affecting the master page.

More information on ASP.NET version 1.0 and 2.0 can be found at http://msdn.microsoft.com/library/, look through the table of contents on the left for areas of interest. ASP.NET information can be found under several different heading, so it pays to scout around. Some of my favorite sections were under .NET Development/Web Applications/Technical Articles.

A final advantage of ASP.NET is that by using either Mono (www.go-mono.com) or Portable.NET (getdotgnu.com), ASP.NET pages can be use with Apache on Linux.

Converting to VB.NET 2005
The VB6 to VB.NET upgrade assistant was greatly improved between VB.NET and VB.NET 2003, and I expect the VB.NET 2005 version will again show great improvements. I have only had an early beta version to test, and have not had very much success with it, possibly because I have not had a chance to work with it very much. In part 1 of this series I gave the http://lab.msdn.microsoft.com/express/vbasic/default.aspx URL where anyone could download the VB.NET 2005 Beta. There is now a newer, experimental (unstable) version available from the same Web site; at the time I wrote this, it had just been posted, and I had not had a chance to download it. It can be downloaded from the bottom of the page; the original, more stable beta can still be downloaded from the top of the page.

Other Conversions
In this section I will cover interoperation between .NET languages and converting between VB.NET, C#, and other languages.

In most cases, once VB6 has been converted to VB.NET, it will not be too difficult to convert it to C#. If the plan is to convert, and not rewrite, it makes sense to convert to VB.NET first.

Microsoft makes a big deal about .NET languages being compatible, even to the point of a class in one language being usable as a base class in a different language, such that some methods in a class can be written in one language, and other methods in the same class can be written in a different language. Well, I have seen the demo and it can work; but be aware that your mileage may vary. There are two issues that can cause problems with interoperability between .NET languages. The first is that for full interoperability, the code in both languages typically needs to be CLI compliant. The second issue is that language behavior can cause problems.

Most, if not all .NET compilers extend the core CLI in one way or another, but for .NET languages to be able to interoperate completely, these extensions cannot, in most cases, be used. The details of this are far beyond the scope of this article, but some examples of these extensions are optional parameters (VB.NET), multiple inheritance (C++), unsafe code (C#, C++), and dynamic languages (Python, Pearl, etc). Languages can also behave differently, for example, VB.NET resolves overloaded functions differently that C#. That is not to say that these languages cannot interoperate, it is just that trying to get different .NET languages to interoperate can be difficult, and is subject to obscure bugs.

Borland has Delphi for .NET, which targets the .NET CLI instead of Windows or Linux. When compiling older Delphi code, it marks places where there are issues such as unsafe code. Delphi 8.0 uses .NET remoting for its data services. Lars Johansson has also created a Delphi to C# converter (it also converts VB6 and VB.NET to C#) at http://w1.311.telia.com/~u31115556/desc/programs.htm#BabbelFisken. The page is in German, as are the sample conversions, but the program's interface is in English.

Several tools and Web sites help convert between C# and VB.NET. None of them are perfect, and some support different features than others. For example, there is a community project at www.codeproject.com/csharp/gbvb.asp that does a fairly good job, but can't convert VB code with constructs like "thing(x)", because it does not know if it is a function (C# thing(x)) or an array (C# thing[x]). There is a commercial VB.NET to C# converter at www.vbconversions.com that claims to have converted the 101 sample projects from Microsoft listed at www.microsoft.com/downloads/details.aspx?FamilyId=08E3D5F8-033D- 420B-A3B1-3074505C03F3&displaylang=en , as well as all the VB.NET sample programs that come with Visual Studio 2003. They have a trial version that is the same as the full version, but limited to 600 lines of VB.NET code. The unlimited version is only $149.00 (U.S.).

The Converting Debate
In my opinion, one of the most important reasons for upgrading is to get access to better tools. Each version of Visual Studio has made big improvements in programmer productivity. Even though VS2003 is a minor upgrade from VS2002, the intellisense and auto-complete in VS2003 is so much better than in VS2002, that when I need to work with VS2002, I save a copy of the project file and upgrade to VS2003; when I am done, I copy the old VS2002 project file back over the VS2003 project file (the changes to C# and the .NET Framework class are small and easy to avoid or correct). Using the old VB6 editor that does not even support scroll mice feels like going back to an old DOS editor. I expect that VS2005 will continue this tradition in general, and with Visual Source Safe (VSS) and Microsoft Team in particular. VSS has not had a significant update since VB4; VS2005 has a completely rewritten version of VSS.

The biggest change is that SQL Server is replacing the old proprietary database; this should improve performance, reliability, and maintainability of the code repository. Microsoft Team is a complete application life cycle framework, similar to packages sold by third-party vendors such as Rational Software. Microsoft has mostly stayed out of this market to avoid competing with Rational, even to point of selling Rational the old Microsoft Test product. Now that IBM has bought Rational, Microsoft is releasing its own products integrated with VS2005. Team will include application and database modeling, bug tracking, workflow, and a new UML like tool. Those staying with VB6 will not have the advantage of any of these tools without buying third-party equivalents; even those will be less capable than the same third-party offering for .NET.

Summary
This completes this series on converting VB6 to VB.NET. The transition is not that difficult, the results tend to be good, there are a lot of tools, books, and articles to help make the transition, and the rewards are great. Microsoft has put VB6 into maintenance mode - it is time to do the same with VB6 code, and make the move to .NET.

More Stories By Dennis Hayes

Dennis Hayes is a programmer at Georgia Tech in Atlanta Georgia where he writes software for the Adult Cognition Lab in the Psychology Department. He has been involved with the Mono project for over six years, and has been writing the Monkey Business column for over five years.

Comments (1)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
SYS-CON Events announced today that DXWorldExpo has been named “Global Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
SYS-CON Events announced today that NetApp has been named “Bronze Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. NetApp is the data authority for hybrid cloud. NetApp provides a full range of hybrid cloud data services that simplify management of applications and data across cloud and on-premises environments to accelerate digital transformation. Together with their partners, NetApp em...
SYS-CON Events announced today that SIGMA Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. uLaser flow inspection device from the Japanese top share to Global Standard! Then, make the best use of data to flip to next page. For more information, visit http://www.sigma-k.co.jp/en/.
SYS-CON Events announced today that N3N will exhibit at SYS-CON's @ThingsExpo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. N3N’s solutions increase the effectiveness of operations and control centers, increase the value of IoT investments, and facilitate real-time operational decision making. N3N enables operations teams with a four dimensional digital “big board” that consolidates real-time live video feeds alongside IoT sensor data a...
Real IoT production deployments running at scale are collecting sensor data from hundreds / thousands / millions of devices. The goal is to take business-critical actions on the real-time data and find insights from stored datasets. In his session at @ThingsExpo, John Walicki, Watson IoT Developer Advocate at IBM Cloud, will provide a fast-paced developer journey that follows the IoT sensor data from generation, to edge gateway, to edge analytics, to encryption, to the IBM Bluemix cloud, to Wa...
There is huge complexity in implementing a successful digital business that requires efficient on-premise and cloud back-end infrastructure, IT and Internet of Things (IoT) data, analytics, Machine Learning, Artificial Intelligence (AI) and Digital Applications. In the data center alone, there are physical and virtual infrastructures, multiple operating systems, multiple applications and new and emerging business and technological paradigms such as cloud computing and XaaS. And then there are pe...
SYS-CON Events announced today that B2Cloud will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. B2Cloud specializes in IoT devices for preventive and predictive maintenance in any kind of equipment retrieving data like Energy consumption, working time, temperature, humidity, pressure, etc.
DevOps at Cloud Expo – being held October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real r...
SYS-CON Events announced today that Massive Networks, that helps your business operate seamlessly with fast, reliable, and secure internet and network solutions, has been named "Exhibitor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. As a premier telecommunications provider, Massive Networks is headquartered out of Louisville, Colorado. With years of experience under their belt, their team of...
SYS-CON Events announced today that Suzuki Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Suzuki Inc. is a semiconductor-related business, including sales of consuming parts, parts repair, and maintenance for semiconductor manufacturing machines, etc. It is also a health care business providing experimental research for...
SYS-CON Events announced today that Fusic will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Fusic Co. provides mocks as virtual IoT devices. You can customize mocks, and get any amount of data at any time in your test. For more information, visit https://fusic.co.jp/english/.
SYS-CON Events announced today that Ryobi Systems will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Ryobi Systems Co., Ltd., as an information service company, specialized in business support for local governments and medical industry. We are challenging to achive the precision farming with AI. For more information, visit http:...
SYS-CON Events announced today that Keisoku Research Consultant Co. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Keisoku Research Consultant, Co. offers research and consulting in a wide range of civil engineering-related fields from information construction to preservation of cultural properties. For more information, vi...
SYS-CON Events announced today that Mobile Create USA will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Mobile Create USA Inc. is an MVNO-based business model that uses portable communication devices and cellular-based infrastructure in the development, sales, operation and mobile communications systems incorporating GPS capabi...
SYS-CON Events announced today that Daiya Industry will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Daiya Industry specializes in orthotic support systems and assistive devices with pneumatic artificial muscles in order to contribute to an extended healthy life expectancy. For more information, please visit https://www.daiyak...
SYS-CON Events announced today that Interface Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Interface Corporation is a company developing, manufacturing and marketing high quality and wide variety of industrial computers and interface modules such as PCIs and PCI express. For more information, visit http://www.i...
In his session at @ThingsExpo, Greg Gorman is the Director, IoT Developer Ecosystem, Watson IoT, will provide a short tutorial on Node-RED, a Node.js-based programming tool for wiring together hardware devices, APIs and online services in new and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using a wide range of nodes in the palette that can be deployed to its runtime in a single-click. There is a large library of contributed nodes that help so...
Elon Musk is among the notable industry figures who worries about the power of AI to destroy rather than help society. Mark Zuckerberg, on the other hand, embraces all that is going on. AI is most powerful when deployed across the vast networks being built for Internets of Things in the manufacturing, transportation and logistics, retail, healthcare, government and other sectors. Is AI transforming IoT for the good or the bad? Do we need to worry about its potential destructive power? Or will we...
SYS-CON Events announced today that mruby Forum will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. mruby is the lightweight implementation of the Ruby language. We introduce mruby and the mruby IoT framework that enhances development productivity. For more information, visit http://forum.mruby.org/.
SYS-CON Events announced today that Nihon Micron will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Nihon Micron Co., Ltd. strives for technological innovation to establish high-density, high-precision processing technology for providing printed circuit board and metal mount RFID tags used for communication devices. For more inf...