Welcome!

Microsoft Cloud Authors: Nick Basinger, Kevin Benedict, Pat Romanski, Liz McMillan, Lori MacVittie

Related Topics: Microsoft Cloud

Microsoft Cloud: Article

Converting VB6 to VB.NET, Part I

A Look at Your Options and When to Use Them

Bad News and Good News
While most VB6 controls convert well, there are exceptions. For example, line and shape controls and commands do not convert very well, and the DB, OLE, and UpDown counter controls do not convert at all. I'll discuss these in more detail in my next article.

Form.Print doesn't exist in VB.NET, and there is no real workaround that I know of. This has got to be the one thing I miss most from VB6. This was also true when I used C++ 6.0 instead of VB6 to write user interfaces. The general solution is to get a bitmap of the form and print that. If you do the scaling right, this can work well, but in many cases, the result is a low quality print. This can be especially true of text. Items that the programmer draws, such as user draw items and general graphics, can be drawn on the printer canvas instead of the screen canvas. Scaled right, this tends to work well, but for controls and other items that draw themselves, creating and printing a bitmap is the only option.

Another feature missing from VB.NET is control arrays. However, there is a fix for this in the Microsoft.VisualBasic.Compatablity.VB6 namespace. This little gem of a namespace has a number of classes that emulate missing VB6 features. Among other things, it contains a control array class for each of the major VB6 controls. The upgrade wizard uses these classes to seamlessly upgrade control arrays. This works really well.

Some of the other things in this namespace are classes for converting VB6 fonts to VB.NET Font objects, image format conversions, and loading resources. Also included are replacements for the VB6 Format, Equ, Imp, ValidateControls, WhatsThisMode, and SendsKeys functions. .NET uses different coordinates from VB6 for windows and graphics. This namespace includes functions to convert between the two. It also contains replacements for File and Dir listboxes, the EXEName and Hinstance functions in the VB6 App object, and some functions missing from the VB.NET Button control. The namespace also has a CopyArray function that allows assigning an array to a variant.

Timer Control
In VB6, setting an interval of 0 disables the timer. The new Timer control doesn't accept a value of 0 (it generates a runtime error) and can only be disabled by setting the Enable property to false. Code that doesn't use an interval of 0 to disable the timer will convert correctly. Code that switches between an interval of 0 (disabled) and a valid value can easily be corrected before converting. More complex code that uses both the Enable and the Interval properties in an "OR'ed" manner may be tricky to upgrade. One instance in which I dealt with this was a VB6 timer controlling a flashing error light. Any one of several subroutines could start the flashing by setting the enabled property to true, which was reset to false after user acknowledgement. The interval property was set to zero to globally disable the alarm. I rewrote the code to use an alarm object that handled all the logic. However, another option would be to write a new Timer class - derived from the .NET Timer class - that overrides the Enable and Interval properties and duplicates the behavior of the VB6 Timer.

 


Imports System
Namespace VB6Timer

Public Class VB6Timera
Inherits System.Windows.Forms.Timer
Private MyInterval As Integer
Private MyEnabled As Boolean

Public Sub New()
MyInterval = MyBase.Interval
MyEnabled = MyBase.Enabled
End Sub

Public Overloads Overrides Property Enabled() As Boolean
Get
Return MyEnabled
End Get
Set(ByVal Value As Boolean)
MyEnabled = Value
If Not Value Then
MyBase.Enabled = False
Else
If Not (MyInterval = 0) Then MyBase.Enabled = True
End If
End If
End Set
End Property

Public Shadows Property Interval() As Integer
Get
Return MyInterval
End Get
Set(ByVal Value As Integer)
If Value = 0 Then
MyBase.Enabled = False
Else
MyBase.Interval = Value
If (MyInterval = 0) And (MyEnabled) Then
MyBase.Enabled = True
End If
End If
MyInterval = Value
End Set
End Property

Protected Overloads Overrides Sub Dispose
(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
End Class
End Namespace

To use this class, compile it under .NET and add a reference to it by browsing for it from the toolbox add component dialog. After the conversion, go to the formdesigner and remove the standard Timer, then add the VB6Timer from the toolbox to the form, and set its properties and name to match the old Timer control. This technique can be used in cases where there are minor differences between a VB6 control and its VB.NET replacement.

Looking Ahead
Over the next two articles, we will finish up general conversions - ADO, ASP, and VB.NET to C# and take a quick look at the VB.NET 2005 upgrade wizard.

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.


IoT & Smart Cities Stories
Early Bird Registration Discount Expires on August 31, 2018 Conference Registration Link ▸ HERE. Pick from all 200 sessions in all 10 tracks, plus 22 Keynotes & General Sessions! Lunch is served two days. EXPIRES AUGUST 31, 2018. Ticket prices: ($1,295-Aug 31) ($1,495-Oct 31) ($1,995-Nov 12) ($2,500-Walk-in)
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 settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
Nicolas Fierro is CEO of MIMIR Blockchain Solutions. He is a programmer, technologist, and operations dev who has worked with Ethereum and blockchain since 2014. His knowledge in blockchain dates to when he performed dev ops services to the Ethereum Foundation as one the privileged few developers to work with the original core team in Switzerland.
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
The challenges of aggregating data from consumer-oriented devices, such as wearable technologies and smart thermostats, are fairly well-understood. However, there are a new set of challenges for IoT devices that generate megabytes or gigabytes of data per second. Certainly, the infrastructure will have to change, as those volumes of data will likely overwhelm the available bandwidth for aggregating the data into a central repository. Ochandarena discusses a whole new way to think about your next...
CloudEXPO | DevOpsSUMMIT | DXWorldEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...
All in Mobile is a place where we continually maximize their impact by fostering understanding, empathy, insights, creativity and joy. They believe that a truly useful and desirable mobile app doesn't need the brightest idea or the most advanced technology. A great product begins with understanding people. It's easy to think that customers will love your app, but can you justify it? They make sure your final app is something that users truly want and need. The only way to do this is by ...
DXWorldEXPO LLC announced today that Big Data Federation to Exhibit at the 22nd International CloudEXPO, colocated with DevOpsSUMMIT and DXWorldEXPO, November 12-13, 2018 in New York City. Big Data Federation, Inc. develops and applies artificial intelligence to predict financial and economic events that matter. The company uncovers patterns and precise drivers of performance and outcomes with the aid of machine-learning algorithms, big data, and fundamental analysis. Their products are deployed...