Should you switch to VB .NET?
Visual Basic .NET looks more like C++ than traditional Basic, so making the move from VB 6 isn't easy—but it may be worth the effort.
Shelley Erickson, National Instruments -- Test & Measurement World, 12/1/2002
|
Microsoft's .NET computing framework stands poised to help you speed test application development. With Visual Studio .NET (Microsoft's .NET programming package), you can write distributed applications, organize large programs, interact with multiple languages, and design for maximum performance. (See "What is .NET?" for more information.)
Visual Studio .NET includes four languages. Of these, Visual Basic (VB) programmers will most likely be drawn to the VB .NET option, but because VB .NET is fundamentally different from earlier versions of the language, it will take time and effort to learn. Before switching to VB .NET, you should consider your options. If you switch, you'll also need to evaluate whether you should migrate test applications written in VB 6.
To develop test applications that take advantage of the .NET framework, you have three basic options:
- Write new applications in VB .NET, but stay with VB 6 for existing applications that run critical tests and require maintenance but not upgrades.
- Convert your VB 6 code to VB .NET code. Doing this will make your applications more compatible with future versions of VB and will give you access to .NET's features, but it also requires rework.
- Opt for another general-purpose language that supports .NET such as C++ or C#. Or, you can move to one of several languages specifically designed for test and measurement such as LabView, Agilent Vee, LabWindows/CVI, or HTBasic.
If your VB 6 applications work well and require little or no maintenance, then you should not convert them to VB .NET. Porting debugged applications risks introducing new bugs into the code and can require time-consuming rework.
For new applications, you'll have to decide if you want to continue developing applications in VB 6, learn VB .NET, or switch to another programming language. While learning VB .NET's syntax and programming requirements takes time, you'll probably need to do it eventually if you choose to stick with Microsoft's programming environment. (See ".NET resources " for a list of books and Web sites that can help you make the transition to VB .NET.)
![]() |
|
Figure 1 In Visual Studio .NET, Microsoft replaces the ActiveX property pages with a .NET property editor. |
To let VB take advantage of the .NET framework, Microsoft built VB .NET from the ground up. The company transformed VB into an object-oriented programming language; thus, VB programmers must learn a new language with a new programming syntax. VB .NET no longer natively supports features such as:
- OLE container control;
- dynamic data exchange (DDE);
- common-object model (COM) objects, including ActiveX components;
- ActiveX property pages; and
- 16-bit and 32-bit whole-number data types.
Today, few test applications use DDE to transfer test data, but many use COM or ActiveX objects to control instruments, create user interfaces, and process test data. Microsoft has replaced COM objects with .NET controls and .NET classes. Table 1 lists some of the software components in VB 6 and their replacements in VB .NET.
Listing 1 contains code samples for calling a COM object in VB 6 and for using a class library in VB .NET; the COM object and the class library provide programming interfaces for a DMM. The .NET version of the code sample demonstrates some of the error-catching features of .NET and how to use .NET add-in components for I/O.
VB .NET also introduces a new method for setting a control's properties. With VB .NET, you set a control's properties either through code or with the Visual Studio .NET property editor (Figure 1). This is a departure from ActiveX controls, which let you set a control's properties either through code or through tabbed property pages (Figure 2).
![]() |
|
Figure 2 ActiveX controls in VB 6 use property pages to set character-istics. |
Seasoned programmers will miss some of VB's familiar features, yet VB .NET offers useful replacements. VB .NET applies the same variable types, arrays, user-defined types, classes, and interfaces as Visual C++ and Microsoft's new language, Visual C# (both come with Visual Studio .NET), and it also includes several new tools.
For example, the .NET framework provides a set of base class libraries, which expose functions such as I/O, database connectivity, and other operating-system features to VB .NET programmers. Microsoft provides more than 6500 functions through .NET base class libraries, all of which follow a consistent programming format; once you learn to use one library, you can easily learn to use others. Figure 3 shows part of a base class library from which you can select a math function to add to your code.
![]() |
|
Figure 3 Base classes in .NET let you add commonly used functions. |
Another noteworthy new tool lets you control memory leaks. When a program opens, Windows allocates memory to that application. When it closes, the application should release all of the allocated memory. If it doesn't, the system will eventually run out of available memory. VB .NET includes a "garbage collection" feature that forces you to free memory when it's no longer needed, thereby minimizing memory leaks.
With .NET, Microsoft no longer uses COM objects such as ActiveX. Fortunately, Microsoft developed a tool that lets you use COM objects in .NET languages. The tool creates a wrapper, called a "Runtime Callable Wrapper," around the COM object to make it compatible with .NET languages. Through the wrapper, COM objects can call functions in .NET class libraries and vice versa.
VB .NET also has a "Conversion Wizard" utility that converts some VB 6 code to VB .NET code. Before you can run most VB 6 code through the conversion tool, you should manually prepare the code to account for differences between the languages. The more preparation you do, the fewer errors you'll have to correct in the converted code.
Among the code you'll need to prepare for conversion are the data types you used in VB 6. Many engineers use the "variant" data type, which accepts any form of data. Variants make for easy, albeit sloppy, coding by not forcing you to specifically define a variable.
You can't use variants with VB .NET because the language replaces variants with objects (Listing 1). Therefore, you'll need to manually search your VB 6 code for variants and change them to more stringently defined variables before you run the Conversion Wizard.
When you run the conversion tool, it will flag the code portions that it can't upgrade and provide links to help you find more information. Remember, though, that just converting an existing application for VB .NET doesn't incorporate any .NET features. To add .NET features to an application, you'll have to write them in VB .NET.
In addition to replacing the variant data type, VB .NET also eliminates the "goto on error" command. While such features make programming in Basic easier than in other languages, they also let you create "spaghetti" code. VB .NET forces you to develop better programming habits, which leads to more maintainable code.
.NET's effectsEventually, .NET will affect your work and, possibly, your career. Writing new applications in VB 6 may get your new test system running in less time than if you have to learn VB .NET, but if you stay with VB 6 too long, you risk falling behind those engineers who make the jump.
For more information"Visual Basic Language Changes," Microsoft, Redmond, WA. msdn.microsoft.com/library/en-us/cpguide/html/cpconvisualbasiclanguagechanges.asp.
| Visual Basic 6.0 | Visual Basic .NET |
| Standard EXE | Windows application |
| ActiveX DLL | Class library |
| ActiveX EXE | Class library |
| ActiveX control | Windows control library |
| ActiveX document | No equivalent. Visual Basic .NET can interoperate with ActiveX documents. |
| DHTML application | No equivalent. Use ASP .NET Web application. |
| IIS application (Web class) | No equivalent. Use ASP .NET Web application. |
| Source: Microsoft Developer Network | |
| Author Information |
| Shelley Erickson is a software product manager at National Instruments. She holds a BS in computer science from the University of Missouri-Rolla. Before moving to product marketing, she worked as an applications engineer supporting National Instruments' software and hardware products. |
|




























