The Wayback Machine - https://web.archive.org/web/20170610212339/http://dotnet.sys-con.com/node/46335

Welcome!

Microsoft Cloud Authors: Andreas Grabner, Stackify Blog, Liz McMillan, David H Deans, Automic Blog

Related Topics: Microsoft Cloud

Microsoft Cloud: Article

Converting VB6 to VB.NET, Part I

A Look at Your Options and When to Use Them

If you're one of the many who have VB6 code, you have three basic options: stay with VB6, convert to .NET, or rewrite from scratch. In this article, we will look at converting VB6 code to VB.NET and C#. I'll discuss when it makes sense to convert versus staying with VB6 or rewriting from scratch. I will cover what converts well and what does not, different ways to do the conversion, how to get code ready to convert, and handling issues after the conversion.

Executive Overview
First, let's get an executive-level overview of where VB6 and VB.NET are at in their life cycles. Note that when I mention VB.NET in this article, I mean all three versions (2002, 2003, 2005). When I talk about a specific version, I will specify the version (such as VB.NET 2002). With the advances in VB.NET 2003, as well as its compatibility with VB.NET 2002, there is little reason to migrate to, or stay with, VB.NET 2002. VB.NET 2005 is still an unstable beta, so the focus here will be on converting to VB.NET 2003.

For those of you who wish to stay with VB6, the key fact is that VB6 developer licenses are perpetual, so developers who have licenses can continue to develop in VB6 for as long as they wish. However, VB6 was released in January 1999 and is approaching six years of age. As a result, it is near the end of its life (VB 1.0 was originally released in 1990). VB6 no longer exists as a stand-alone product - mainstream support ends in about six months - and all support will end three years after that. Currently, to get a new VB6 license, you must either buy VB.NET and then request a VB6 downgrade disk (for about $20), or get an MSDN subscription and download it from the archives. However, I wouldn't be surprised to see these dates extended.

VB6 can be a viable option for small- to medium-sized programs with limited lifespans, for several years to come. But for large, long-term projects that will need to be maintained for a number of years, VB6 is rapidly becoming a non-option.

VB.NET was in widespread beta, with some commercial applications shipping in 2001. Release 1.0 came in 2002 and version 1.1 showed up in 2003. VB.NET is clearly ready for primetime. As a bonus, Mainsoft Corp., Mono, and Portable.NET are preparing to take VB.NET code cross-platform.

VB.NET can be cheap; many VB6 developers are MSDN members and already have access to VB.NET. The stand-alone VB.NET product is about $110, and adventuresome folk can download a free copy of VB.NET 2005 that contains the upgrade wizard at lab.msdn.microsoft.com/vs2005/get/default.aspx. A DVD (or CD) of the VS2005 Enterprise version beta can be ordered for a shipping and handling fee from the same Web page. Serious developers and corporations will typically have one of the more expensive MSDN subscriptions and access to all of this and more.

Options
If you have VB6 code, your main choices are to stay with VB6, convert the code to VB.NET or C#, or rewrite the code from scratch in VB.NET, C#, or Java. If you plan to rewrite in Java, you are probably reading the wrong article (and probably the wrong magazine; may I suggest our fine sister publication JDJ).

Whether or not to convert a program is always a case-by-case decision, driven by several competing factors such as the quality of the original code, cost, programmer availability, customer base, etc. On one hand, the only clear case where not going through at least a trial conversion would make sense is if the product is at the end of its life, with only bug fixes being implemented, and no plans for future versions. On the other hand, few large VB6 programs will convert to VB.NET without some significant rewriting. In almost all cases, I think going through at least a quick "probe" conversion is a good exercise for almost all projects - even if the converted code is not used, some valuable lessons will be learned.

Although the focus of this article will be on VB6 to VB.NET conversions, those of you moving to C# or looking at a complete VB.NET rewrite can still benefit from a conversion to VB.NET. For those of you looking at moving to C#, there are several tools (we will take a quick look at a couple of them later) that convert VB.NET to C# (and back), so it makes sense to convert to VB.NET as a step on the way to C#. If you're planning to do a complete rewrite to either VB.NET or C#, you can use the VB.NET conversion wizard to get a head start. In most programs, there are blocks of code that implement algorithms or business logic. These blocks of converted code can be pasted into a new project, speeding development for those choosing to do a complete rewrite.

Also consider that there are different levels and methods of conversion. If you have an ActiveX control written in VB6, a true conversion would be to rewrite it as a WinForm control in VB.NET. A better option might be to wrap the control in a .NET wrapper and use it from .NET while converting and testing. Shipping a VB6 ActiveX control with a .NET application can complicate the install because the VB runtime and associated files must also be installed. This is the same installation that is required if the control is installed with a VB6 application, but it is obviously more complex than the simple XCopy install of pure .NET applications.

Another way in which this ActiveX wrapper trick can be used is on forms that do not convert well, regardless of the reason. If the form can be moved to a separate project that was created as an ActiveX control project, the resulting ActiveX control can be added to a replacement form in VB6 or to a VB.NET project. Any form that can be separated from the rest of the program in this manner can be converted to an ActiveX control and used from .NET using .NET's built-in interop capabilities. In addition, we will see that most simple DLLs can be easily used directly from .NET.

In converting from VB6 to VB.NET 2003, three areas will be looked at: general VB6 code, ADO database code, and ASP Web page code. In this article, I concentrate on using the upgrade wizard to convert general VB code to VB.NET. In the future articles, I will finish general conversion issues, covering ADO, ASP, C#, and VB.NET 2005.

Before We Even Start
Remove dead code; you cannot have trouble with code you do not convert. Remove variables that are never used and subroutines that are never called. I converted one application that was large enough to have a number of associated programs, such as configuration programs, format converters, upgrade tools, and some ActiveX controls. Most of these utilities shared header files (WIN32 API declare statements and user type definitions) with the main application, but most of these programs only used a few of the functions in the headers. Other applications did not use anything in some of the headers. By removing the unused files and functions from the project, I was able to convert all the utilities much quicker. This allowed some functionality to be shown quickly, and provided the experience needed to tackle the main application.

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 (2)

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
In this presentation, Striim CTO and founder Steve Wilkes will discuss practical strategies for counteracting fraud and cyberattacks by leveraging real-time streaming analytics. In his session at @ThingsExpo, Steve Wilkes, Founder and Chief Technology Officer at Striim, will provide a detailed look into leveraging streaming data management to correlate events in real time, and identify potential breaches across IoT and non-IoT systems throughout the enterprise. Strategies for processing massiv...
The current age of digital transformation means that IT organizations must adapt their toolset to cover all digital experiences, beyond just the end users’. Today’s businesses can no longer focus solely on the digital interactions they manage with employees or customers; they must now contend with non-traditional factors. Whether it's the power of brand to make or break a company, the need to monitor across all locations 24/7, or the ability to proactively resolve issues, companies must adapt to...
SYS-CON Events announced today that CA Technologies has been named "Platinum Sponsor" of SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CA Technologies helps customers succeed in a future where every business - from apparel to energy - is being rewritten by software. From planning to development to management to security, CA creates software that fuels transformation for companies in the applic...
In his keynote at @ThingsExpo, Chris Matthieu, Director of IoT Engineering at Citrix and co-founder and CTO of Octoblu, focused on building an IoT platform and company. He provided a behind-the-scenes look at Octoblu’s platform, business, and pivots along the way (including the Citrix acquisition of Octoblu).
SYS-CON Events announced today that IBM has been named “Diamond Sponsor” of SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California.
The consumer IoT market is growing at an astounding rate – device ownership increased 259% from 2015 to 2016. In her session at @ThingsExpo, Noelani McGadden, Vice President of IoT at PlumChoice, will present thought-provoking insights from a recent survey, while exploring the opportunities and challenges as the market continues to grow. The data highlights which types of devices consumers currently own and are planning to purchase, the reasons why they’re purchasing these devices and their pr...
SYS-CON Events announced today that Striim will exhibit at SYS-CON's 20th International Cloud Expo® | @ThingsExpo New York, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Striim™ (pronounced “stream”) is an enterprise-grade, real-time integration and intelligence platform. Striim makes it easy to ingest high volumes of streaming data – including enterprise data via log-based change data capture – for real-time log correlation, cloud integration, edge process...
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...
SYS-CON Events announced today that Interoute, owner-operator of one of Europe's largest networks and a global cloud services platform, has been named “Bronze Sponsor” of SYS-CON's 20th Cloud Expo, which will take place on June 6-8, 2017 at the Javits Center in New York, New York. Interoute is the owner-operator of one of Europe's largest networks and a global cloud services platform which encompasses 12 data centers, 14 virtual data centers and 31 colocation centers, with connections to 195 add...
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...
SYS-CON Events announced today that Clouber will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Clouber offers Migration as a Service (MaaS) across Private and Public Cloud (AWS, Azure, GCP) including bare metal migration to cloud. Clouber’s innovative technology allows for migration projects to be completed in minutes instead of weeks. For more updates follow #clouberio
Amazon started as an online bookseller 20 years ago. Since then, it has evolved into a technology juggernaut that has disrupted multiple markets and industries and touches many aspects of our lives. It is a relentless technology and business model innovator driving disruption throughout numerous ecosystems. Amazon’s AWS revenues alone are approaching $16B a year making it one of the largest IT companies in the world. With dominant offerings in Cloud, IoT, eCommerce, Big Data, AI, Digital Assista...
SYS-CON Events announced today that Striim will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Striim is pronounced "stream", with two i's for integration and intelligence. The company was founded in 2012 as WebAction, with a mission to help companies make data useful the instant it's born. The leaders behind the Striim platform thrive on building technology companies that raise expectations for how the wor...
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with the 21st International Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. @ThingsExpo Silicon Valley Call for Papers is now open.
New competitors, disruptive technologies, and growing expectations are pushing every business to both adopt and deliver new digital services. This ‘Digital Transformation’ demands rapid delivery and continuous iteration of new competitive services via multiple channels, which in turn demands new service delivery techniques – including DevOps. In this power panel at @DevOpsSummit 20th Cloud Expo, moderated by DevOps Conference Co-Chair Andi Mann, panelists will examine how DevOps helps to meet th...
SYS-CON Events announced today that Outscale will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Outscale's technology makes an automated and adaptable Cloud available to businesses, supporting them in the most complex IT projects while controlling their operational aspects. You boost your IT infrastructure's reactivity, with request responses that only take a few seconds.
In his session at @ThingsExpo, Arvind Radhakrishnen will discuss how IoT offers new business models in banking and financial services organizations with the capability to revolutionize products, payments, channels, business processes and asset management built on strong architectural foundation. The following topics will be covered: How IoT stands to impact various business parameters including customer experience, cost and risk management within BFS organizations.
SYS-CON Events announced today that CAST Highlight has been named "Bronze Sponsor" of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. CAST Highlight is an ultra-rapid code-scanning SaaS offering that identifies potential IT risks and cost savings opportunities across distributed application portfolios. By delivering data and insights on the health of portfolios, CAST Highlight provides IT leaders with objectivity and c...
In his opening keynote at 20th Cloud Expo, Michael Maximilien, Research Scientist, Architect, and Engineer at IBM, will motivate why realizing the full potential of the cloud and social data requires artificial intelligence. By mixing Cloud Foundry and the rich set of Watson services, IBM's Bluemix is the best cloud operating system for enterprises today, providing rapid development and deployment of applications that can take advantage of the rich catalog of Watson services to help drive insigh...
In order to meet the rapidly changing demands of today’s customers, companies are continually forced to redefine their business strategies in order to meet these needs, stay relevant and continue to see profitable growth. IoT deployment and development is integral in this transformation, and today businesses are increasingly seeing the value of investing their resources into IoT deployments. These technologies are able increase ROI through projects such as connecting supply chains or enabling sm...