How To Prepare Yourself For Moving From VB6 To VB.NET

How To Prepare Yourself For Moving From VB6 To VB.NET

In this article, I will make a few guesses of how you canchange your coding style and prepare yourself already today for the transition,to make it as smooth as possible. In the article I will focus on components,especially for the server-side.

Moving from VB6 to VB.NET doesn’t seem tobe a small step. Still, we will do the transition in the future because of moreimprovements than I had dared to hope for. Probably, you won’t port all yourcode day one and a lot of your code will probably benefit much more from arewrite rather than a port. Anyway, perhaps you like to start to prepareyourself as early as possible.

Beta 1 has been outfor a while, but what I write in this article is actually just guesses.In the history there have been several guesses that we are laughing at today.One example of such a guess (at the time it was created I don’t think they sawit as a guess) was something like “the world will not need more than fivecomputers for all the computations in the future”. Another one was somethinglike “a PC will never need more than 640 KB of RAM”. Hopefully my guesses willnot be that funny in the future. In a year or so we’ll know.

A SHORT INTRO TO VB.NET

I’m notgoing to spend a lot of time describing what VB.NET is. I’d just like to give ashort intro to it before the real article starts.

As youprobably know by now, Microsoft is upgrading all its Visual Studio (VS)languages right now. One example of that is that VB6 will be changed to VB.NET.At first you will benefit from several techniques that are shared between allthe VS languages such as a new ADO.NET, ASP.NET, WinForms,WebForms, Web Services and the .NET Framework (that is a rich class librarywith a lot of functionality). You will also find a new Integrated DevelopmentEnvironment (IDE) and a new debugger. Both are to be used for all the .NETlanguages.

VB.NETwill be a full-fledged .NET-language and because of that it can use all thejust mentioned functionality, plus a whole lot more. Old problems with VB willbe gone such as only the single threaded apartment-model (STA) formulti-threading and VB.NET will also be a much more object-oriented languagethan before. The latter you will find in the shape of for exampleimplementation inheritance, class methods and the possibility to sendparameters to constructors. You will finally have structured error handling andthe possibility to force explicit cast and to force declaration of datatypesfor variables. Not a single day too early, right?

Thecode you write in VB will be compiled to Intermediate Language (IL). The ILwill then be executed with the Common Language Runtime (CLR) (after it has beencompiled to machine code). That is exactly what is happening with C# too forexample and both those languages (and the rest of the .NET-languages) willprobably have more or less the same performance characteristics. (It dependsupon how efficient IL they will generate.)

AVAILABLE INFORMATION

There is a lot of informationavailable already about VB.NET and also information about how to upgrade. Acommon tip is to be as explicitas possible in your code. An example of that is to write out both ByRef and ByVal in your parameter lists even though you will get the effect from ByRef if you don’t say anything else. The reasonfor this is almost to be called well known by now. In VB.NET, ByVal will be used if nothing else has beenstated. So, it’s effectively the opposite from VB6. The upgrade wizard willhopefully take care of this well, but if you will need to directly change habitwhen you jump between VB6 and VB.NET projects (which most of us will have to dofor a long time) it’s probably a very good idea to use this tip.

Fromnow on in this article, I will not mention tips that I’ve read anywhere else sothe rest will be my own guesses that I will have to be embarrassed for myselfif they prove wrong.

RUSH TO UPGRADE?

Justone more thing before we get going. Will it be important to rush to upgradeyour VB6 components to VB.NET components? As I see it, it will not. I will mostprobably let my components that are in production when VB.NET ships, stay inVB6 for a while (or perhaps for a very long time). The interoperabilityseems to be strong and therefore it will probably be perfectly alright to letyour old VB6 components cooperate with new ones that you definitely (hmmm,should be perhaps) will rush to create in VB.NET. (Please note though thatthe interoperability layer will decrease performance slightly.)

Anexception to this is if you have COM+ components that really would benefit alot from those COM+ component services that you can’t use today such as objectpooling. Anyway in most cases you don’t have to rush to the upgrading process.Even if that is the case, why not prepare yourself for the eventual upgrade?So, let’s take a look at what I think should be done today.

CENTRALIZE CODE

Sometimesyou hear that VB6 isn’t good for reusing code because you don’t haveimplementation inheritance. In my opinion implementation inheritance is justone of several mechanisms for reusing code. You can of course use ordinary codemodules for that, but also put code to share in class modules that youinstantiate from several other classes.

Several of you might think that codemodules are a bit retro, but I use them quite a bit for highly centralized codesnippets in my COM+ components. I have had stability problems earlier withother solutions for those snippets and therefore I use code modules and I willleave it that way until VB.NET. In VB.NET I will get more or less the samebehavior with class methods (and I can continue to use code modules too if Iwant).

Sayingthat you should centralize and reuse code instead of using copy and paste isprobably nothing new for you. Still I think that it can be taken even furtherin most applications that I’ve looked behind the surface of. (That goes forthose I’ve written myself too.) If you have a code snippet at one place only, thenit’s as easy as it can be to upgrade that one to a new approach. OK, usingsearch and replace is quite effective too, but you will always have the risk ofmissing something!

If youfind that copy and paste has been used too much in VB components, the situationis often much worse when it comes to stored procedures and ASP code. (At leastfor the code I’ve seen. Ehrm… And also that I’ve written a long time agoin the past.) This is out of the scope for this article, but since I gotexcited, I couldn’t help myself for adding this paragraph.

CHANGE YOUR NAMING CONVENTIONS

Ipromised that I would only write about my own tips and not duplicate what I’veread from others. One thing about VB.NET that you perhaps have heard fromseveral places is that an Integer in VB6 will be a Short in VB.NET and that a Long in VB6 will be an Integer in VB.NET. I will not say that once again.

What Iwill say is that I think it can be wise to change your naming conventions todayif you prefix your variables to describe the datatype. I used to use int and lng as the prefix in VB6 to describe Integer and Long, but I’ve started to use sht and int instead. Since I’ve used my old prefixes for eight years orsomething like that, it will take some time to kill the old habit.

Skip theflaming e-mails please. I’m aware of that not everybody thinks type prefixesshould be used. I like them and I will continue to use them in the future.Since I’m changing my mind quite often, I will probably skip using them aftereight years or so.

READ GAMMA ETC (AGAIN)

Gamma,Helm, Johnson, Vlissides had their best selling book Design Patterns releasedin 1995. It’s still a bestseller after all those years. How come? (I guess thecomputer industry is one of the rare that think of five years as all thoseyears.)

Proposalsfor how to design applications never goes out of fashion, right? As a matter offact I think it will be important to be more design-centric than what is commonfor the average VB6 programmer today. I think that is very good since I havebeen nagging about that for years. (If you say something often enough, itfinally becomes true, right?)

If Itry to be serious for a while, I would really like to stress the tip to readGamma’s book

CONTINUE TO USE USER DEFINED INTERFACES

It tookme a long time to start enjoying user-defined interfaces, but after a couple ofminutes I saw the light. Ever since then, I’ve been using them a lot anddefinitely think I’ve benefited a lot from them.

I don’tknow if it’s because of my instinct for adjusting myself or something else, butthe last few years I haven’t missed implementation inheritance much and that ismostly because of VB’s support for separating the interfaces from theirimplementation by using user-defined interfaces.

At oneperiod in time, I thought that Microsoft told us about the problems withimplementation inheritance in large real world applications because they didn’thave the support for it in COM and VB. Then I read Szyperski’s book ComponentSoftware. Beyond Object-Oriented Programming and understood that the problemswere well-known in the academic research since a long time back.

Yes, Iknow that we will have implementation inheritance in VB.NET, and I willdefinitely use it. (As I understand it, Microsoft has at least partly solvedsome of the classical problems with implementation inheritance.) I also knowthat I will definitely use user-defined interfaces a lot in the future too.Since VB.NET won’t have support for multiple inheritance, you will give addedsupport to classes by implementing interfaces. You will also use user-definedinterfaces in situations similar to when you use them today.

BTW,Microsoft has also refined the support quite a bit for user-defined interfacesin VB.NET, but that is another story.


SIMULATE TRY CATCH FINALLY

FinallyVB.NET will have support for structured error handling with Try, Catch and Finally! In the Try-block you write the ordinary code, in the Catch-block you take care of errors and in the Finally-block you have code that you want to beexecuted no matter if there is an error or not.

Eventhough the error handling in VB6 is quite primitive you can get close to thesemantics of Try, Catch and Finally and by doing that you will geta solid structure for the methods in your components already today.

In thearticle Exampleof code structure for COM+ component I describe a code structure for acomplete COM+ component, but most of the attention is being paid to the errortrapping and how to simulate Try, Catch and Finally.

BUILD FOR COM+ AND ITS PROGRAMMING MODEL

COM+Component Services is dead! Long live .NET Component Services! What I’m sayingis that the COM+ programming model that you’ve come to love, seem to be more orless exactly the same with .NET. (The rumor says that the way to use .NETComponent Services will change a bit in beta 2, but that is as far as I knowtoday just rumors.)

As aVB-programmer you will with VB.NET get access to more component services thanbefore so it will just be more fun tomorrow. I’m sure you will enjoy COM+Component Services today also (and also see a lot of benefits in using them) somy recommendation is clear. Get accustomed to them and use them if you haven’tyet!

SUMMARY

Hopefully this article has added a wholebunch of tips to your collection of information for how you can prepareyourself but also your VB6 components already today for upgrading to VB.NET.The more design-aware you are and the more well-designed your VB6 componentsare, the more possible it will be to port you and your components to VB.NET. Thatis my summarized guess!

RELATED

devx-admin

devx-admin

Share the Post:
Battery Breakthrough

Electric Vehicle Battery Breakthrough

The prices of lithium-ion batteries have seen a considerable reduction, with the cost per kilowatt-hour dipping under $100 for the first occasion in two years,

Economy Act Soars

Virginia’s Clean Economy Act Soars Ahead

Virginia has made significant strides towards achieving its short-term carbon-free objectives as outlined in the Clean Economy Act of 2020. Currently, about 44,000 megawatts (MW)

Renewable Storage Innovation

Innovative Energy Storage Solutions

The Department of Energy recently revealed a significant investment of $325 million in advanced battery technologies to store excess renewable energy produced by solar and

Development Project

Thrilling East Windsor Mixed-Use Development

Real estate developer James Cormier, in collaboration with a partnership, has purchased 137 acres of land in Connecticut for $1.15 million with the intention of

USA Companies

Top Software Development Companies in USA

Navigating the tech landscape to find the right partner is crucial yet challenging. This article offers a comparative glimpse into the top software development companies

Battery Breakthrough

Electric Vehicle Battery Breakthrough

The prices of lithium-ion batteries have seen a considerable reduction, with the cost per kilowatt-hour dipping under $100 for the first occasion in two years, as reported by energy analytics

Economy Act Soars

Virginia’s Clean Economy Act Soars Ahead

Virginia has made significant strides towards achieving its short-term carbon-free objectives as outlined in the Clean Economy Act of 2020. Currently, about 44,000 megawatts (MW) of wind, solar, and energy

Renewable Storage Innovation

Innovative Energy Storage Solutions

The Department of Energy recently revealed a significant investment of $325 million in advanced battery technologies to store excess renewable energy produced by solar and wind sources. This funding will

Renesas Tech Revolution

Revolutionizing India’s Tech Sector with Renesas

Tushar Sharma, a semiconductor engineer at Renesas Electronics, met with Indian Prime Minister Narendra Modi to discuss the company’s support for India’s “Make in India” initiative. This initiative focuses on

Development Project

Thrilling East Windsor Mixed-Use Development

Real estate developer James Cormier, in collaboration with a partnership, has purchased 137 acres of land in Connecticut for $1.15 million with the intention of constructing residential and commercial buildings.

USA Companies

Top Software Development Companies in USA

Navigating the tech landscape to find the right partner is crucial yet challenging. This article offers a comparative glimpse into the top software development companies in the USA. Through a

Software Development

Top Software Development Companies

Looking for the best in software development? Our list of Top Software Development Companies is your gateway to finding the right tech partner. Dive in and explore the leaders in

India Web Development

Top Web Development Companies in India

In the digital race, the right web development partner is your winning edge. Dive into our curated list of top web development companies in India, and kickstart your journey to

USA Web Development

Top Web Development Companies in USA

Looking for the best web development companies in the USA? We’ve got you covered! Check out our top 10 picks to find the right partner for your online project. Your

Clean Energy Adoption

Inside Michigan’s Clean Energy Revolution

Democratic state legislators in Michigan continue to discuss and debate clean energy legislation in the hopes of establishing a comprehensive clean energy strategy for the state. A Senate committee meeting

Chips Act Revolution

European Chips Act: What is it?

In response to the intensifying worldwide technology competition, Europe has unveiled the long-awaited European Chips Act. This daring legislative proposal aims to fortify Europe’s semiconductor supply chain and enhance its

Revolutionized Low-Code

You Should Use Low-Code Platforms for Apps

As the demand for rapid software development increases, low-code platforms have emerged as a popular choice among developers for their ability to build applications with minimal coding. These platforms not

Cybersecurity Strategy

Five Powerful Strategies to Bolster Your Cybersecurity

In today’s increasingly digital landscape, businesses of all sizes must prioritize cyber security measures to defend against potential dangers. Cyber security professionals suggest five simple technological strategies to help companies

Global Layoffs

Tech Layoffs Are Getting Worse Globally

Since the start of 2023, the global technology sector has experienced a significant rise in layoffs, with over 236,000 workers being let go by 1,019 tech firms, as per data

Huawei Electric Dazzle

Huawei Dazzles with Electric Vehicles and Wireless Earbuds

During a prominent unveiling event, Huawei, the Chinese telecommunications powerhouse, kept quiet about its enigmatic new 5G phone and alleged cutting-edge chip development. Instead, Huawei astounded the audience by presenting

Cybersecurity Banking Revolution

Digital Banking Needs Cybersecurity

The banking, financial, and insurance (BFSI) sectors are pioneers in digital transformation, using web applications and application programming interfaces (APIs) to provide seamless services to customers around the world. Rising

FinTech Leadership

Terry Clune’s Fintech Empire

Over the past 30 years, Terry Clune has built a remarkable business empire, with CluneTech at the helm. The CEO and Founder has successfully created eight fintech firms, attracting renowned

The Role Of AI Within A Web Design Agency?

In the digital age, the role of Artificial Intelligence (AI) in web design is rapidly evolving, transitioning from a futuristic concept to practical tools used in design, coding, content writing

Generative AI Revolution

Is Generative AI the Next Internet?

The increasing demand for Generative AI models has led to a surge in its adoption across diverse sectors, with healthcare, automotive, and financial services being among the top beneficiaries. These

Microsoft Laptop

The New Surface Laptop Studio 2 Is Nuts

The Surface Laptop Studio 2 is a dynamic and robust all-in-one laptop designed for creators and professionals alike. It features a 14.4″ touchscreen and a cutting-edge design that is over

5G Innovations

GPU-Accelerated 5G in Japan

NTT DOCOMO, a global telecommunications giant, is set to break new ground in the industry as it prepares to launch a GPU-accelerated 5G network in Japan. This innovative approach will

AI Ethics

AI Journalism: Balancing Integrity and Innovation

An op-ed, produced using Microsoft’s Bing Chat AI software, recently appeared in the St. Louis Post-Dispatch, discussing the potential concerns surrounding the employment of artificial intelligence (AI) in journalism. These

Savings Extravaganza

Big Deal Days Extravaganza

The highly awaited Big Deal Days event for October 2023 is nearly here, scheduled for the 10th and 11th. Similar to the previous year, this autumn sale has already created

Cisco Splunk Deal

Cisco Splunk Deal Sparks Tech Acquisition Frenzy

Cisco’s recent massive purchase of Splunk, an AI-powered cybersecurity firm, for $28 billion signals a potential boost in tech deals after a year of subdued mergers and acquisitions in the