This FAQ is designed to answer common issues that arise when beginning the
process of porting Visual Basic 6.0 projects or ASP 3.0 web applications to
Visual Basic .NET. It is also useful for Visual Basic developers who are
investigating the Microsoft .NET platform and anyone learning Visual Basic
.NET.
Rather than addressing questions on the details of the Microsoft .NET
architecture, this document attempts to answer higher-level issues that may not
be covered elsewhere, but are pertinent to individuals getting started with
.NET. We also provide “best-practices” strategies and recommendations for
working with Microsoft .NET.
This FAQ is sponsored by Callisto
Systems, Inc. - A Microsoft Partner providing .NET consulting and
custom .NET software development. Callisto Systems specializes in migrating
legacy applications from Visual Basic 6.0, Visual C++, and ASP to modern
ASP.NET and Windows Forms technology.
Many of our customers ask us questions like the ones that are covered by this
document. Callisto Systems has developed this FAQ to provide a central
resource to catalog those questions and answers for public consumption.
If you need assistance with .NET consulting and development, please contact us
at: info@callistosystems.com.
This FAQ is evolving over time and is being updated to address new questions we
receive. If you have a question you would like to see answered in the FAQ,
please send email to: faq@callistosystems.com. If
you have a FAQ entry to contribute, please let us know. We will make sure to
credit you for your contribution.
Table of Contents
Section 1 - General
1.1 Should I upgrade to .NET?
1.2 Should I switch to C#?
1.3 Should I switch to Java?
1.4 Can VB6 and VB.NET coexist on the same
machine?
1.5 What is a good strategy for upgrading
my legacy Visual Basic code?
1.6 What is the difference between a
Windows Forms application and an ASP.NET web application?
1.7 Can a Windows Form application be
easily converted into an ASP.NET application (or vice versa)?
1.8 Should I build a Windows Forms
application or an ASP.NET web application?
1.9 What is a Web Service?
1.10 What is .NET Remoting?
Section 2 - Language
2.1 What are the most significant language
changes from VB 6.0 to Visual Basic .NET?
2.2 What is Exception Handling?
2.3 What is Inheritance?
2.4 What is Polymorphism?
2.5 What are Attributes?
2.6 What is serialization?
2.7 How do I compile my code into a DLL
that can be shared with other .NET applications?
Section 3 - Upgrade Wizard
3.1 What is the Upgrade Wizard?
3.2 How long does it take the Upgrade
Wizard to run?
3.3 What are common issues with Upgrade
Wizard generated code?
3.4 What is a good strategy for preparing
code for the Upgrade Wizard?
3.5 Is there a tool to help prepare for
running the Upgrade Wizard?
3.6 Is the Upgrade Wizard included with
the Standard Edition of Visual Basic .NET?
3.7 Is the Upgrade Wizard in Visual Studio
2003 a new version?
3.8 I ran the Upgrade Wizard for several
hours and it never finished. What should I do next?
3.9 How do I quickly upgrade a small piece
of Visual Basic 6.0 code?
3.10 Does the VB6 Upgrade Tool convert
ADO to ADO.NET?
3.11 How does the VB6 Upgrade Tool handle
Variants?
3.12 What does the Upgrade Wizard do with
arrays?
3.13 I ran the Upgrade Wizard and I
received an error message. What should I do?
3.14 I’m getting an error message that
states “The VB6 Upgrade Tool is not installed.”
3.15 Does Microsoft provide resources to
help with upgrade issues?
Section 4 - COM Components
4.1 Is COM still a viable technology?
4.2 Can I reference my legacy COM
components in a Windows Form application?
4.3 Can I reference my legacy COM
components in an ASP.NET application?
4.4 Can Visual Basic .NET create COM
components that are accessible from legacy applications?
4.5 Can I upsize my legacy COM components
to Visual Basic .NET?
Section 5 - ASP.NET Applications – Upgrading from ASP 3.0
5.1 Can I use the new Developer Studio
environment to maintain legacy ASP code?
5.2 Can I run my ASP 3.0 application under
ASP.NET with minimal changes?
5.3 Can I run ASP 3.0 pages side-by-side
with ASP.NET pages?
5.4 Can I share Session information
between ASP 3.0 pages and ASP.NET pages?
5.5 How do I debug ASP 3.0 code?
5.6 What are the most significant changes
between VBScript and Visual Basic .NET?
Section 6 - References
6.1 Recommended Websites
6.2 Recommended Books
Section 1 - General
If the Visual Basic 6.0 source code that you are concerned about is part of an
application that is still evolving and being updated, then the answer is Yes.
Legacy applications that are not being enhanced should run correctly on future
Windows platforms without problems. However, if you are performing new
development or working on an existing application that is intended to be
enhanced over the coming years, upgrading should be of great benefit. Microsoft
.NET offers new levels of ease of development and stability for Windows
platforms.
MSDN provides a list of compelling reasons to upgrade:
http://msdn.microsoft.com/vbasic/productinfo/topten/upgrade.aspx
Generally speaking, most Visual Basic 6.0 developers will be most comfortable
adjusting to the new Visual Basic .NET language instead of C#. The C#
language is primarily intended for C++ developers who are looking for an
upgrade path into .NET. C# is also a good choice for Java developers who are
switching to .NET. The functional differences between C# and Visual Basic
.NET are minor. The most obvious differences are:
- Visual Basic .NET includes upgrade utilities for automatically translating
Visual Basic 6.0 source code into Visual Basic .NET.
- C# uses C++ style curly braces { }. Visual Basic programmers may be
more comfortable with the familiar If-Then / End If syntax from VB 6.0.
- C# uses case-sensitive variable names. Visual Basic programmers may be more
comfortable with the code editor automatically adjusting the case of
identifiers.
- C# statements end with semi-colons (;). This is familiar for C++
developers, but may be annoying for Visual Basic programmers.
- C# uses C++ style variable declarations (ex. int x;). Visual Basic
programmers may prefer the declaring variables using the Dim statement. (Dim X
As Integer)
Java is primarily of interest for developers that are concerned about deploying
onto Macintosh or Unix platforms. If your customers require your
application to run on high-end Unix servers, then you may have no choice but to
switch to Java. Windows Servers provide a compelling alternative to Unix
servers. If there is a possibility of encouraging your customers to deploy a
Windows Server, then .NET may still be a viable option. Also, ASP.NET
applications can deliver a compelling cross-platform solution that runs
consistently on all platforms with a standard web browser.
It should be noted that Java development on Unix is substantially different
from Visual Basic development on Windows. Developers that are lacking a C++
background on Unix are likely to experience a difficult learning curve if they
are attempting to switch from Visual Basic.
Yes. The two development environments can be installed and run simultaneously
on the same machine. It is reasonable to have an application where some
components are authored and maintained in Visual Basic 6.0, while other
components are handled by Visual Basic .NET.
There are a number of possible approaches and the correct answer will depend on
your situation. Generally it’s best to approach the process incrementally. One
potential path is to use .NET only for new projects. Another angle is to
upgrade legacy components that should be reusable in newer .NET projects.
Another strategy would be to leave legacy COM components and ActiveX controls
behind. These components can be accessed through .NET’s COM interop
features.
The correct strategy is a complex decision that should be considered
carefully. Once you have chosen which legacy projects should be upgraded,
the Visual Basic .NET Upgrade Wizard can provide a good first pass at
translating your code to .NET. Generally, the output from this tool will be a
close, but not perfect, transfer of your code to .NET. Specific areas of your
code will probably need to be adjusted by hand to accommodate the changes in
Visual Basic .NET.
Windows Forms applications are Microsoft .NET’s version of the traditional
Windows desktop GUI application. Most Visual Basic 6.0 applications fall
into this category.
ASP.NET web applications are the .NET equivalent of an ASP 3.0 web application.
The development tools for creating ASP.NET applications have advanced
significantly since ASP 3.0. ASP.NET offers many of the conveniences that
Visual Basic developers are accustomed to (including a forms editor and a
tightly integrated debugger). ASP.NET development is quite similar to
developing Windows Forms applications in Visual Basic .NET.
ASP.NET can generate HTML that can be rendered by most common web browsers on
any platform. A web application is a good choice if you need to deliver your
application to multiple platforms without requiring an installation footprint.
Generally, the answer is no. Even though the GUI controls that are used by each
type of application share similar property names, methods, and functionality,
their capabilities and behaviors are generally different. The most significant
difference is that ASP.NET applications rely on HTTP requests that have minimal
state. This requires a different style of development than desktop
applications. Non-GUI components, database access, and the basic design of the
application are generally transferable between application types. But, for the
most part, Windows Forms applications are fundamentally different from web
applications.
This is a complex question where the answer depends on your business needs. Web
applications are preferable in cases where customer installation hassles must
be minimized and the user interface requirements of the application are
relatively simple. Web applications are limited by the capabilities of the
client’s web browser software. Web applications offer significant benefits in
terms of software installation, software updates, usage tracking, and
centralization.
Windows Forms applications are ideal in cases where a rich user interface is
important and high performance is a key requirement. An important new
consideration is that Windows Form applications can use web services to
communicate with remote databases that are behind corporate firewalls. Many
traditional desktop applications are good candidates for translation to Windows
Forms applications.
A web service is a component that is remotely accessible using the SOAP
protocol. It is a similar concept to the legacy DCOM approach. The key
difference is that web services are easy to configure and are designed to
travel using the HTTP network protocol. This makes them easy to use across
corporate firewalls. Web services are based on the standard SOAP protocol and
therefore accessible across different platforms. Java developers have
appropriate tools for creating and/or consuming web services that are
compatible with .NET. Web services are ideal for transferring information
between processes that are separated by large distances on the Internet, as
well as to inter-operate between different operating system architectures.
.NET Remoting is similar to web services except the SOAP protocol is not
required. .NET Remoting is based on a proprietary Microsoft standard that
offers higher performance for .NET applications that need to communicate with
one another. This approach is appropriate for machines that are located close
together and can communicate with less concern about firewall and security
issues. .NET Remoting enables richer, higher performance communication without
the overhead of the SOAP protocol, but it lacks compatibility with applications
that are not developed in .NET. It is generally not appropriate for
communicating with clients that are separated by large distances on the
Internet.
Section 2 - Language
Visual Basic .NET introduces a wide range of changes from Visual Basic 6.0.
Some of the more significant are:
- Introduction of new features like structured exception handling
and inheritance
- Common library functionality is available through the Microsoft
.NET Framework
- Variant type has been replaced with the Object type
- Parameter passing defaults to ByVal instead of ByRef
- Calls to a Sub procedure require parenthesis (just like calling
Function)
- Integer types are 32 bit and Long types are 64 bit
A complete list of changes and revisions is too large and extensive for this
document.
Microsoft provides a comprehensive list of changes here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaconprogrammingelementschangesinvb7.asp
Exception handling is a new more robust approach to error handling that
replaces Visual Basic 6.0’s On Error Goto pattern. Visual Basic .NET exception
handling is based on Try/Catch blocks that are very similar in structure to C++
style error handling. When a block of code fails, a .NET Exception object is
passed to an error handler. The Exception object provides detailed information
about what failed (including a full stack trace to the offending line of code).
Visual Basic .NET exception handling further extends traditional Visual Basic
error handling by adding the capability to nest multiple levels of error
handling inside one procedure/function.
See this article for more detail about Visual Basic .NET exception handling.
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q315965&ID=kb;en-us;Q315965&SD=MSDN
Inheritance has traditionally been an important quality of object-oriented
programming. It is commonly used in languages like Java or C++.
This feature is new for Visual Basic programmers in Visual Basic .NET.
Inheritance is the ability to create a class that is derived from another
class. A child class inherits all of its parent’s qualities (properties,
methods, and events) and optionally has the ability to adjust those qualities.
This is a very useful technique for building software and is used heavily
throughout the .NET library.
Additional information about inheritance can be found here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaconInheritanceForBasicLanguage.asp
Polymorphism is the ability to manipulate different types of objects using the
same property and method names (as if the objects had identical types). This
ability to work with objects of differing types homogeneously can be very
powerful. Polymorphism has traditionally been an important quality of
object-oriented programming. It is commonly used in languages like Java
or C++. Polymorphism can be separated into two categories: Interface
Polymorphism and Inheritance Polymorphism. Interface Polymorphism was
available in Visual Basic 6.0 using the Implements keyword. Polymorphism that
is based on inheritance is a new feature in Visual Basic .NET.
Inheritance Polymorphism is the ability to treat an inherited child class like
it was an instance of its parent class. A good example of this is the .NET
Framework Class Library’s Control class. The Control class provides a common
basis for most other standard control types. This makes it possible to
manipulate lists of specific types of Controls using only the generic methods
from the Control class.
Attributes are declarative tags that can be inserted in front of an element in
code to indicate special qualities that should applied to that item. Attributes
are denoted by values that are located between < > symbols. Commonly used
attributes defined by the CLR include:
<WebMethod> - Indicates a method that should be exposed as part of a web
service
<DllImport> - For importing unmanaged Win32 functions from DLLs
<Serializable> - Indicates an object that can be serialized
.NET also allows developers to define custom attributes , which
may be applied to code and retrieved and evaluated at runtime.
Serialization is the ability to convert an object into a stream of text or
binary data. In this form, objects can easily be read or written to files or
passed across the network.
MSDN provides a good article on serialization:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet09252001.asp
Code is shared between applications using .NET assemblies. An assembly is a DLL
that contains compiled .NET classes and a manifest that indicates the contents
of the assembly. Assemblies are easy to make by creating a “Class Library” type
of project with the New Project command. Assemblies that were created elsewhere
are easily added to a project through the References list for a project.
MSDN provides a good article on creating reusable components:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconWalkthroughCreatingWFCComponent.asp
Section 3 - Upgrade Wizard
The Upgrade Wizard is a tool for automatically converting Visual Basic 6.0 code
into Visual Basic .NET code. It generally provides a good first pass at
converting a project. There are some types of code that it is unable to
convert. In these cases, the Upgrade Wizard will mark the offending code with
comments and continue processing.
The Upgrade Wizard is a very useful tool, but in most cases, additional manual
coding is required to complete the conversion effort.
The amount of time varies depending on the size and complexity of the code
being processed. In some cases, the Upgrade Wizard can spend several
hours processing before successfully completing an upgrade. It can be
tempting to cancel the process because it is taking a very long time when it is
actually performing as intended.
The most common problems are associated with areas that do not translate
directly onto the Visual Basic .NET platform.
MSDN provides a good summary here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconthingstoconsiderbeforemigrating.asp
Before upgrading, you should inventory your code for use of features that are
no longer supported or supported differently in Visual Basic .NET. You
should also have a basic knowledge of how the Upgrade Wizard converts code and
what its limitations are.
MSDN provides a summary of issues to consider:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconpreparingvisualbasic60applicationformigration.asp
Yes. Microsoft provides a free tool for examining your Visual Basic 6.0 code.
The Code Advisor for Visual Basic 6.0 is available here:
http://www.microsoft.com/downloads/details.aspx?familyid=a656371a-b5c0-4d40-b015-0caa02634fae&languageid=f49e8428-7071-4979-8a67-3cffcb0c2524&displaylang=en
Yes. The Standard Edition of Visual Basic .NET 2003 includes the Upgrade
Wizard. In Visual Basic .NET 2002, only the Enterprise Edition included the
Upgrade Wizard.
It's a new version, with many improvements. Most important is the ability to
upgrade User Controls and Web Classes.
When you cancelled the wizard, was an error message displayed? Check the
upgrade log file for possible hints about what went wrong. By default, the log
file is output to the same directory as the VB 6.0 project and has the same
name as the project, but with a .log extension.
Open a code editor window in Visual Basic .NET. On the Tools menu, select
“Upgrade Visual Basic 6.0 Code”. Paste your legacy code into the upgrade
window.
No, There isn’t a one-to-one mapping between ADO and ADO.NET, so it leaves ADO
code alone. ADO objects remain functional and are referenced through .NET’s COM
interop layer.
The Variant type in Visual Basic 6.0 has been replaced with the .NET Object
type. Object is the generic data type that all .NET classes are derived
from. For compatibility, the VarType() function can be applied to an
Object instance to retrieve a type value from the VariantType enumeration.
In Visual Basic .NET, all arrays are zero-based. If your code uses a one based
array, then the lower boundary will be shifted to zero and an UPGRADE_WARNING
comment will be added to your code. If your code depends on the lower boundary
of the array being one, then you will need to make modifications.
Visual
Basic Upgrade Wizard error
Upgrade
failed: Exception occurred: Could not load referenced component:
SomeControl.ocx(6.0.3)
You
need to install this component before you upgrade the project. It is
recommended you install VB6.0, with all referenced components, and ensure the
application compiles and runs before upgrading.
What should I do?
This problem is caused by running the Upgrade Wizard on a machine that does not
have the required OCX controls installed with a design-time license. To correct
the problem, you will need to run the developer installer for the
component. If this problem happens with a Microsoft component, it is
probably because you do not have Visual Basic 6.0 installed on the machine
where you are running the Upgrade Wizard.
Here is a support page that discusses the problem:
http://support.microsoft.com/default.aspx?scid=kb;en-us;318597
PRB: Error Message: The Visual Basic 6.0 Upgrade Tool Is Not Installed on This
Computer
Here is a support page that discusses the problem:
http://support.microsoft.com/default.aspx?scid=kb;en-us;320305&Product=vbNET
3.15 Does Microsoft provide resources to help with upgrade issues?
Here are some useful websites:
http://msdn.microsoft.com/vbasic/using/migrating/default.aspx
http://www.msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvb600/html/vb6tovbdotnet.asp
Section 4 - COM Components
Yes, but it is being phased out. .NET applications are able to use legacy COM
components and ActiveX controls. .NET applications are also able to
export functionality as COM components that can be used by applications that
are developed using legacy tools. In general, it is preferable to migrate
towards pure .NET solutions that offer the benefits of a simpler development
model, improved stability, and easier deployment.
Yes. COM components can be imported by adding COM references to your project.
ActiveX controls can be added to the Windows Forms toolbox by right-clicking
the Toolbox and selecting “Add/Remove Items…”.
Yes. COM components can be imported by adding COM references to your project.
ActiveX controls can be added to the Windows Forms toolbox by right-clicking
the Toolbox and selecting “Add/Remove Items…”.
It should be noted that many legacy COM components were built using an STA
threading model. All components built in Visual Basic 6.0 are based on the STA
model. Many ATL components also use STA. ASP.NET applications run using
the free-threaded MTA model for improved performance. This is an important
change since ASP 3.0.
As a result of the change to the MTA model, there are potential issues with
using STA COM components from ASP.NET. STA components cannot be created inside
of the MTA apartment. The “aspcompat”
page directive provides a workaround that allows the ASP.NET process to create
an additional thread for handing STA components.
There is an MSDN article that describes how to use the aspcompat directive:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconCOMComponentCompatibility.asp
Yes. Classes that are created with Visual Basic.NET can be exposed as COM
objects and are therefore accessible via any technology that supports COM. MSDN
provides a walkthrough of this process:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaconIntroductionToCOMInteroperability.asp
Yes. The Upgrade Wizard can migrate components that were created in Visual
Basic 6.0. The upgraded components can continue to expose their COM interface
for consumption by legacy applications. Remember that upgrading introduces a
new dependency on the .NET Framework. Legacy applications that use a COM
component that is implemented with .NET will require that the .NET Framework is
installed.
Section 5 - ASP.NET Applications – Upgrading from ASP 3.0
Yes. The new environment works well as a replacement for Visual InterDev. You
can create a new empty ASP.NET project and add your existing .asp and .htm
files. Server-side debugging of ASP 3.0 pages is also well supported by Visual
Studio .NET.
ASP.NET has been designed to accommodate code upgraded from ASP 3.0 with a
minimum number of changes. It’s possible to perform an incremental conversion
where an ASP 3.0 page is adjusted to execute with the ASP.NET engine. This
approach will provide some of the benefits of .NET. However, to take full
advantage of the new features of ASP.NET, each page will probably need to be
rewritten.
MSDN provides a set of steps for migrating ASP 3.0 code to the ASP.NET engine:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskmigratingasppagetoasp.asp
5.3 Can I run ASP 3.0 pages side-by-side with ASP.NET pages?
Yes. But, ASP 3.0 applications are processed by the asp.dll ISAPI extension and
ASP.NET pages are handled by aspnet_isapi.dll. An important consideration is
that the two environments are separate. Session and Application state variables
are not shared. ASP.NET and ASP 3.0 can exist side by side in a single web
application. But, information must be manually passed between the two
environments.
5.4 Can I share Session information between ASP 3.0 pages and ASP.NET pages?
Yes, but the process is not automatic. Session and Application state variables
are not shared. The ASP.NET Session object is completely separate and
independent from the ASP 3.0 Session object. It is possible to have a web
application that has a mix of ASP 3.0 and ASP.NET pages. But information that
must be passed between environments must be marshaled across the query string
or some other mechanism.
5.5 How do I debug ASP 3.0 code?
Sponsored by Callisto Systems, Inc. -
A Microsoft Partner providing .NET consulting and custom .NET software
development
ASP 3.0 debugging support can be activated in Project Properties –
Configuration Properties – Debugging.
MSDN provides an overview:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vxtskdebuggingglobalasafile.asp
5.6 What are the most significant changes between VBScript and Visual Basic
.NET?
In ASP.NET, the server-side code for generating the HTML for your web
application may be written in Visual Basic .NET instead of VBScript. This
is a major improvement. Visual Basic .NET is a robust programming language
instead of a lightweight scripting tool. The most significant advantage is that
Visual Basic is a strongly typed language where VBScript handles all variables
as Variant types. Visual Basic .NET offers a wide range of improvements over
VBScript including exception handling, reusable components from the .NET
Framework, and the added performance benefit of compiled code.
Section 6 - References
If you are looking for additional information about Upgrading to Visual Basic
.NET, we highly recommend the following sources of information:
MSDN: http://msdn.microsoft.com
Microsoft Press: http://mspress.microsoft.com
Programming
Microsoft ASP.NET
by Dino Esposito
Programming
Microsoft Visual Basic .NET
by Francesco Balena
Programming
Microsoft Visual Basic 6.0
by Francesco Balena
Upgrading
Microsoft Visual Basic 6.0 to Visual Basic .NET
by Ed Robinson, Michael Bond, Robert Ian Oliver
This document is sponsored by Callisto
Systems, Inc. - A Microsoft Partner providing .NET consulting and
custom .NET software development.
Copyright © 2004 Callisto Systems, Inc. All Rights Reserved.