Port your Visual Basic 6.0 to Visual Basic. net

Source: Internet
Author: User
Tags access database microsoft access database

Port your Visual Basic 6.0 to Visual Basic. net

Abstract: This article recommends to Visual Basic developers who are about to port their applications to Visual Basic. net. This article includes
New Features of Visual Basic. net, Introduction to upgrade tool information, and smooth upgrade of Visual Basic 6 to Visual Basic. net
Guidance

Title
What is Visual Basic. Net?
Why is Visual Basic. net not 100% compatible?
Upgrade to Visual Basic. net
Working in both Visual Basic 6.0 and Visual Basic. net

Basic Structure
Browser-based programs
Server/Customer Engineering
Single application
Data
Language improvements

Upgrade
Variant to object
Integer to short
Property syntax
Visual Basic Form to Windows form
Interface

Upgrade report notes
Programming
Use advance binding (early-binding)
Data Storage
Default attributes without Parameters
Boolean data type
Avoid null Propagation
Use an array with a lower boundary of 0
Use a constant instead of a constant
Array and fixed-length string in user-defined type
Avoiding Genetic Effects
Windows API call
Considerations for forms and controls

Overview:
This article recommends to Visual Basic developers who want to port their applications to Visual Basic. net. This article includes
Introduction to the Visual Basic. net upgrade tool and instructions for smoothly upgrading the Visual Basic 6 structure to Visual Basic. net
Visual Basic. NET will automatically upgrade when you open the Visual Basic 6.0 Project, but in most cases you need
Make some changes to the Visual Basic 6.0 program opened under basic. net. The purpose of this article is to change the original program as much as possible.
Less efficient.
Note: Visual Basic. NET is still under development, so some of the following details may be changed. The following guidance does not guarantee
The Code does not need to be modified.

What is Visual Basic. Net?
Visual Basic. NET is the next generation of Visual Basic. However, it is not simple to add some new features on Visual Basic 6.0,
Microsoft re-designed the product so that developers can easily develop distributed applications, such as web-based programs and multi-layer systems.
Visual Basic. Net has two form packages, Windows form and web form. A new version of ADO is used to accept offline data sources.
To improve the security of type data and provide a low-level structure to meet the needs of high-level developers.
These new features provide a new development window for Visual Basic developers: through web forms and ADO. net, you can quickly develop scalable
Through inheritance, the language truly supports object-oriented programming and Windows Forms.
It supports visual inheritance. Now, expanding a program is as simple as copying executable files and controls to another directory.
Visual Basic. NET is now fully integrated into other Microsoft Visual Studio. NET languages, not only through different languages
Develop components and inherit from the cross-language. You can derive classes written in one language from the classes written in another language.

Why does Visual Basic. net not provide 100% inheritance?
There are two ways to design Visual Basic. Net: Renovation and full creation. To provide users with as many new features as possible (for example
To provide full access to the new platform, and to make visual basic completely transferred to the next generation of Web applications. Zheng
The actual choice is to create a new one.

For example, many new features in Windows forms can be implemented by adding new controls and properties to the existing code. However
Provides many inherent features of new windows forms, such as security and visual inheritance.

An important goal is to make visual basic code fully integrated into code written in other languages, such as microsft C # (read C sharp)
Or visual c ++. And allows Visual Basic developers to make full and simple use of the. NET Framework, without the need to use
Windows API call. All Visual languages are used in the same way as other common runtime languages.
Data Definition type, array, user-defined array, class, and interface. However, we need to make some sacrifices, such as fixed-length strings and
Arrays with 0 Numbers and lower bounds are no longer supported.

Visual Basic has now become a real object-oriented language with some inconsistent features, such as gosub/return statements and defint
It has been removed from the new language.
This result makes Visual Basic more dynamic and one of the most effective tools for developing Windows applications.
It is also the best tool for developing next-generation Web sites.

Upgrade to Visual Basic. net
In principle, Visual Basic. Net can transfer traditional Windows developers to build the next-generation Web and multi-layer applications. So, your code
Upgrade required to adapt to Visual Basic. net
After you use Visual Basic. Net to open the Visual Basic 6.0 Project, you can use the automatic upgrade tool to upgrade and create a new
Project Based on Visual Basic. net. This upgrade is one-way, because the new visual basic. Net project cannot be created in Visual Basic 6.0.
Open.
After the project is upgraded, Visual Basic. Net modifies the syntax and converts Visual Basic 6.0 forms to Windows Forms. Connect
In general, you still need to make some modifications manually, because the automatic upgrade tool cannot do everything for you.
To help change the original code, after your project is upgraded, Visual Basic. net adds an "upgrade Report" to the project to list all the problems,
Add comments in the code to indicate the changes you need to make. These comments will be listed in the "to do" list in the task list window, so you can
To view the relevant code, you only need to double-click related items in the task list. Every task and upgrade
The list items in the report have related online help titles to help you more.

Allows Visual Basic 6.0 and Visual Basic. Net to work simultaneously
Visual Basic. Net supports upgrading the project generated by Visual Basic 6.0. If your project is written in VB 1-5, you must first upgrade
Grade Visual Basic 6.0 Project, compile, save, and then upgrade to Visual Basic. net.
Visual Basic. NET and Visual Basic 6.0 can be installed on the same system and run simultaneously. Similarly, earlier versions or their
COM components written in the language can also be integrated into Visual Basic. net. For example, you can drag and drop an ActiveX program written in Visual Basic 6.0.
Control to the Windows form of Visual Basic. net, and use the COM component of Visual Basic 6.0 in the Visual Basic. Net class.
The components compiled by Visual Basic. NET are a little different from those compiled by Visual Basic 6.0.
The garbage collection method is released, so there may be a certain delay between the object is deleted and the object is actually released from the memory.
In addition, Visual Basic. NET provides binary compatibility between Visual Basic. NET components and Visual Basic 6.0. Expand now
It is easier to configure multiple components. to configure a component file, you only need to simply copy the file to the directory (regsvr32 is not required ). Group
To upgrade to the new version, you need to overwrite the new file. All you have to do is verify that the new component's similar method is compatible with the old component.

Structure
The. NET platform enhances the structure of the previous version platform and provides better support for application scalability and distribution features. For example, offline data access
Q. HTTP-based message transfer file configuration. To obtain the above features, you need to use Visual Basic. net.

Browser-based applications
Visual Basic 6.0 and Visual Studio 6 provide the following technologies for creating browser-based Internet and Intranet applications:
Webclasses
DHTML Projects
ActiveX documents
Active Server Pages (ASP)

ASP. NET is introduced in Visual Basic. net, ASP. NET is an enhanced version of ASP, and added to the web forms structure, web
Forms are an important component of the. NET architecture. A web form contains two parts: an HTML file and a source program file. HTML file
Description page. The source program file is used to respond to and control page events. Creating a web form is as simple as creating a visual basic form.
Its WYSIWYG interface is designed in the same way as the current Visual Basic. The following figure demonstrates the design of a web form: (additional image: webforms1.gif)

Web forms run on the server and generate HTML pages based on the html3.2 standard to be sent to the client. This is the same as ASP,
The order is compiled and executed, which is much faster than ASP for interpretation execution.

The following describes how to seamlessly transfer browser-based applications developed by Visual Basic 6.0 to Visual Basic. net.
.

We recommend that you use the Microsoft multi-layer architecture to develop your application, use ASP to develop the interface, and use Visual Basic 6.0 or visual
COM components developed in C ++ 6.0, Visual Basic. Net fully supports ASP. You can use ASP, ASP. NET, and web forms to expand your applications at the same time.
Visual Basic 6.0 or vc6 commercial components can be directly used in Visual Basic. Net without being upgraded or modified.

DHTML applications that contain DHTML pages and client DLL cannot be automatically upgraded to Visual Basic. net. We recommend that you
Develop these applications in section 6.0. Like DHTML projects, ActiveX documents are not supported by Visual Basic. net. Cannot be upgraded automatically. We created
Discussion: You can develop ActiveX documents in Visual Basic 6.0 or convert ActiveX documents to custom controls. However
ActiveX documents and DHTML applications can be integrated into Visual Basic. NET technology.

Webclasses will no longer exist in Visual Basic. net. Web applications will be upgraded to ASP. NET; however, after the automatic upgrade
You still need to make some changes. Existing Web applications can be integrated into web forms and ASP applications of Visual Basic. net,
We recommend that you use ASP's Windows DNA platform in the new project. For more information about Windows DNA, visit the Microsoft DNA site:
Http://msdn.microsoft.com/isapi/gomscom.asp? Target =/DNA/

Customer/Server Engineering
Visual Basic 6.0 provides the following techniques for creating client/server applications:
Visual Basic Form
Microsoft Transaction Server (MTS)/COM + intermediate layer object
User Control

Visual Basic. NET provides a new form package: Windows Forms. Compared with Visual Basic 6.0 forms, Windows Forms use different
But most of them are compatible. When your project is upgraded, Visual Basic forms are automatically upgraded to Windows Forms. Below is
Windows form example: (additional image windowsforms1.gif)

Visual Basic. NET provides more powerful support for developing MTS and COM + server components in the middle layer. Use a unified debugger,
You can perform step-by-step debugging from the client to the MTS/COM + component and then to the client. At the same time, the integrated debugger supports both the MTS and COM + components.
Debugging (the component must be compiled in native code mode, including symbolic debugging information and not optimized ).

Visual Basic. Net also provides a new intermediate layer component: Web Services (Web Server ). The Web server is included in ASP. NET,
Shows the structure: (additional image: webservices.gif)

You can use HTTP to pass allowed method requests through the firewall. Data transmission uses XML based on industrial standards, allowing other languages
And platform access to their functions. Although MTS transactions are no longer supported, you still have reason to upgrade your application to the Web server.
Distributed transactions and cross-platform operations are required. With Visual Basic. net, you can perform simple drag-and-drop operations.

After your project is upgraded, the user control is upgraded to the Windows control. However, the custom property tag settings and the acceleration key settings are not upgraded.

Single-layer applications
Visual Basic 6.0 supports the following types of single-tier applications:
Single-tier database applications
Visual Basic plug-in
Common applications and games.

A single-layer database program uses Visual Basic to access the Microsoft Access database. These applications can be upgraded to visual
Basic. net
Now Visual Basic. Net integrated development environment (IDE) has been fully integrated as part of Visual Studio. net ide, Visual Basic. net
The extension module Visual Basic. Net, which contains the new language-neutral language (Language-neutral), is now equivalent to Visual Studio. NET.
Add-ins, you can use any language in Visual Studio. NET to develop plug-ins. For example, you can compile a Visual Basic. Net plug-in
To draw the color of the Visual C # form or add comments to the VB class. To support these new functions, Visual Basic. Net no longer supports the old
Extension module, you need to change the extension objects in the original program.

Many programs are applied to utility programs ). The application needs to operate the file and set the registry. Visual Basic. net
It also provides new features. For example, an unexpected handle can capture file system errors and use the registry class to manipulate the registry. Note that
Depends on the performance characteristics program, such as the game needs to be improved, because Visual Basic. net
It provides new system performance features. For game development in Visual Basic. net, you can use Microsoft directx7, or use the new GDI: GDI +,
GDI + includes many new features and provides Alpha mixing, anti-sawtooth support, and more image file formats for simple 2-D games.

Database Operations
Visual Basic 6.0 provides the following types of database access methods:
ActiveX Data Objects (ADO)
Remote Data Objects (rdo)
Data access objects (DAO)

Visual Basic. Net contains the enhanced version of ADO, called ADO. net. Ado. Net aims to operate offline data. Ado Distribution
Applications provide more powerful support. Ado. Net allows you to bind a database to Windows Forms controls and web forms.
By making some small changes, Dao, rdo, and ADO can still be used in Visual Basic. net. However, Visual Basic. Net does not support Dao.
It is bound to a control, Database Control, or rdo user connected to the rdo database. We recommend that you include Dao and rdo in the application or still use
Before Visual Basic 6.0 is developed or upgraded to Visual Basic. net, change them to ADO data binding.

Language improvements
We can see in many programming forums or newsgroups that C ++ advocates call VB a toy language ). Among them, VB is the most
It is criticized that it does not really support Object-Oriented Programming (OOP ).
In the New Visual Basic, these will all be in the past. Visual Basic. NET will truly support oop. Inheritance and Polymorphism
(Polymorphism) and overloading ). Of course. Including some new data structures and structural error control (error
Handing) and thread. These will be supported by the new VB.

Inheritance
Suppose you have compiled a basic class that only contains one function named baseclass:

Function getcustomername ()
'Do some stuff
End Function

If you want to create a new class and use the getmermername function in baseclass. But do not want to rewrite a code. Then, through inheritance,
You can write a new class like this:

Inherits baseclass

Function getcustomerid ()
'Do some stuff
End Function

Heavy Load
Overload is the process of creating two functions with the same name but different parameter attributes. Assume that the getcustomid function is used based on input and output.
The ID of the user. This function may be of the following two types:

Function getcustomerid (custname as string) as integer
'Obtain the user ID using the user name
End Function

Function getcustomerid (purch as long) as integer
'Obtain the user ID based on the shopping order number.
End Function

By reload, you can call the same function based on different types of input.
In fact, the current VB provides the function of overloading to some extent. Consider the following function:

Function getcustomid (VIN as variant) as long
Getcustomid = vin
End Function

You can call

Id = getcustomid ("123 ")
Or
Id = getcustomid (123)

So why should we introduce heavy load in the new version? This is because the new visual basic introduces new features: type security (default
Type Safety ). In Visual Basic. net, the variant type no longer exists. For more information, see the upgrade section below.

Polymorphism
Polymorphism is the process of redefining a function in a class. For example, you need to create a subclass Based on the baseclass class, but you need to re-
Compile the getcustomername function. In the new vb version, you can write it as follows:

Inherits baseclass

Function getorders ()
Overrides function getorders ()
...
End Function

Thread
The structure of the New Visual Basic language will contain the establishment of multiple threads. An example of a thread creation is as follows:

Set T = new thread (New threadstart
(Addressof (baseclass. function1 ))

From the above example, we can also see that the addressof function in Visual Basic. NET will actually return the pointer of the function. This is an API call,
For example, callback functions are helpful.

Error Handling)
Another major improvement of Visual Basic. NET is error handling. Visual Basic will provide try... Catch... Finally structure, just like
In Delphi (Microsoft's original article is: Just like those "respectable" ages :-)). For example:

Sub safewrite ()
Try
Open "testfile"
...
Write #1
Catch
Kill "testfile"
Finally
Close #1
End try
End sub

Upgrade
After the code is upgraded, Visual Basic. Net creates a new upgrade project. Here are a few examples to illustrate the upgrades your code has made.

Variant to object
Earlier versions of Visual Basic Support the variant data type, which can be set to any original data class except fixed-degree strings
Empty, error, nothing, and null. In Visual Basic. net, the object data type can be set to any original data type and empty,
Error, nothing, null, and object pointer. After your project is upgraded to Visual Basic. net, any variant definition will be changed to object.
Similarly, when you insert code in the editor, the variant keyword is replaced with an object.

Integer to short
In Visual Basic 6.0, 16 bits are now called short. The number of 32bit is called INTEGER (the number of 64bit is called long ). After the project is upgraded,
The data definition will be changed as follows:

Dim X as integer
Dim y as long
Changed:

Dim X as short
Dim y as integer

Attribute syntax
Visual Basic. Net makes more intuitive changes to the syntax of Custom Attributes and combines get and set into one. For example, the original attributes are as follows:

Property get myproperty () as integer
M_myproperty = myproperty
End Property
Property let myproperty (newvalue

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.