Welcome!

Microsoft Cloud Authors: Elizabeth White, Yeshim Deniz, Serafima Al, Janakiram MSV, John Katrick

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) View Comments

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.


Most Recent Comments
Jonathan Pierce 01/15/05 01:32:10 PM EST

Once you have converted your code to VB.NET, our Decompiler.NET product can assist you in reliably converting your VB.NET code base to C# without sacrificing correct compile or runtime behavior. We have many customers using the product to convert VB.NET, Delphi 8, and J# code to C# which compiles and runs correctly immediately without the need for any manual editing. We even support using the VS Designer on the converted code. You can download a free trial version of our product from http://www.junglecreatures.com/

@ThingsExpo Stories
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
Imagine if you will, a retail floor so densely packed with sensors that they can pick up the movements of insects scurrying across a store aisle. Or a component of a piece of factory equipment so well-instrumented that its digital twin provides resolution down to the micrometer.
In his keynote at 18th Cloud Expo, Andrew Keys, Co-Founder of ConsenSys Enterprise, provided an overview of the evolution of the Internet and the Database and the future of their combination – the Blockchain. Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settle...
Product connectivity goes hand and hand these days with increased use of personal data. New IoT devices are becoming more personalized than ever before. In his session at 22nd Cloud Expo | DXWorld Expo, Nicolas Fierro, CEO of MIMIR Blockchain Solutions, will discuss how in order to protect your data and privacy, IoT applications need to embrace Blockchain technology for a new level of product security never before seen - or needed.
BnkToTheFuture.com is the largest online investment platform for investing in FinTech, Bitcoin and Blockchain companies. We believe the future of finance looks very different from the past and we aim to invest and provide trading opportunities for qualifying investors that want to build a portfolio in the sector in compliance with international financial regulations.
Leading companies, from the Global Fortune 500 to the smallest companies, are adopting hybrid cloud as the path to business advantage. Hybrid cloud depends on cloud services and on-premises infrastructure working in unison. Successful implementations require new levels of data mobility, enabled by an automated and seamless flow across on-premises and cloud resources. In his general session at 21st Cloud Expo, Greg Tevis, an IBM Storage Software Technical Strategist and Customer Solution Architec...
Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
When shopping for a new data processing platform for IoT solutions, many development teams want to be able to test-drive options before making a choice. Yet when evaluating an IoT solution, it’s simply not feasible to do so at scale with physical devices. Building a sensor simulator is the next best choice; however, generating a realistic simulation at very high TPS with ease of configurability is a formidable challenge. When dealing with multiple application or transport protocols, you would be...
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
We are given a desktop platform with Java 8 or Java 9 installed and seek to find a way to deploy high-performance Java applications that use Java 3D and/or Jogl without having to run an installer. We are subject to the constraint that the applications be signed and deployed so that they can be run in a trusted environment (i.e., outside of the sandbox). Further, we seek to do this in a way that does not depend on bundling a JRE with our applications, as this makes downloads and installations rat...
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
DX World EXPO, LLC, a Lighthouse Point, Florida-based startup trade show producer and the creator of "DXWorldEXPO® - Digital Transformation Conference & Expo" has announced its executive management team. The team is headed by Levent Selamoglu, who has been named CEO. "Now is the time for a truly global DX event, to bring together the leading minds from the technology world in a conversation about Digital Transformation," he said in making the announcement.
In this strange new world where more and more power is drawn from business technology, companies are effectively straddling two paths on the road to innovation and transformation into digital enterprises. The first path is the heritage trail – with “legacy” technology forming the background. Here, extant technologies are transformed by core IT teams to provide more API-driven approaches. Legacy systems can restrict companies that are transitioning into digital enterprises. To truly become a lead...
Digital Transformation (DX) is not a "one-size-fits all" strategy. Each organization needs to develop its own unique, long-term DX plan. It must do so by realizing that we now live in a data-driven age, and that technologies such as Cloud Computing, Big Data, the IoT, Cognitive Computing, and Blockchain are only tools. In her general session at 21st Cloud Expo, Rebecca Wanta explained how the strategy must focus on DX and include a commitment from top management to create great IT jobs, monitor ...
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
The IoT Will Grow: In what might be the most obvious prediction of the decade, the IoT will continue to expand next year, with more and more devices coming online every single day. What isn’t so obvious about this prediction: where that growth will occur. The retail, healthcare, and industrial/supply chain industries will likely see the greatest growth. Forrester Research has predicted the IoT will become “the backbone” of customer value as it continues to grow. It is no surprise that retail is ...