Migrate your Visual Basic 6.0 to Visual Basic.Net

zhaozj2021-02-08  254

Migrate your Visual Basic 6.0 to Visual Basic.Net

Summary: This article recommends Visual Basic developers who are ready to transplant their applications to Visual Basic.NET. Article included

Introduction to the information of the Visual Basic.net upgrade tool, and how to smoothly upgrade Visual Basic 6 Structures to Visual Basic.net

title

What is Visual Basic.net?

Why is Visual Basic.net not provide 100% compatible?

Upgrade to Visual Basic.Net

Work in Visual Basic 6.0 and Visual Basic.NET

Basic structure introduction

Browser-based program

Server / Customer Engineering

Single-layer application

data

Language improvement

upgrade

Variant to Object

Integer to SHORT

Property syntax

Visual Basic Form to Windows Form

interface

Upgrade report notes

Programming introduction

Use pre-binding (Early-binding)

Data storage

Default attribute without parameters

Boolean data type

Avoid NULL propagation

Use 0 lower bound array

Use constant without using a value represented by constant

User-defined arrays and fixed length strings

Avoid genetic effects

Windows API call

Considering the form and control

Overview:

This article recommends Visual Basic developers who are ready to port their applications to Visual Basic.NET. Article included

Introduction to the information of the Visual Basic.net upgrade tool, and how to smoothly upgrade Visual Basic 6 Structures to Visual Basic.net

Visual Basic.Net will automatically upgrade when opening Visual Basic 6.0 project, but in most cases you need to be in Visual

The Visual Basic 6.0 program opened under Basic.Net do some changes. The purpose of this article is that your changes in the original procedures are as possible.

Less and effective.

Note: Visual Basic.net is still in development, so some of the details below may change, the following instructions are not guaranteed in the final product

There is no need to change from the post code.

What is Visual Basic.net?

Visual Basic.net is the next generation of Visual Basic. It is not simple to add some new features in Visual Basic 6.0.

Microsoft has redesigned products to enable developers to develop distributed applications, such as web-based programs and multi-layer systems.

There are two form packages, Windows forms, and web forms in Visual Basic.NET; a new version of ADO is used to accept offline data sources; new language

In the words, the original keywords are removed, 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: you can quickly develop scalable through web forms and ADO.NET

Web site; through inheritance, this language implements true support object-oriented programming; Windows Form

It supports visual inheritance; now the extension is as simple as copying executable files and controls to another directory.

Visual Basic.net is now fully integrated in other Microsoft Visual Studio .NET languages, not only can be different languages

Developing components, and inheriting through crosslinks, you can derive classes written in another language in a class written in a language.

Why does Visual Basic.NET do not provide 100% inheritance?

There are two directions in designing Visual Basic.NET: refurbishment and completely new. For new features (such as inheritance, and threads), for use, in order to provide full access to the new platform, and to enable Visual Basic to fully transfer to a next-generation web application. positive

The index is completely new.

For example, many new features in the Windows Form can be implemented by adding new controls and properties in the existing code. But this will be sacrificed

Many intrinsic features of the new Windows form, such as security, and visual inheritance.

An important goal is to make the Visual Basic code fully integrated into code written in other languages, such as Microsft C # (Read C Sharp)

Or Visual C . And let Visual Basic developers can completely and simple to use the function of the .NET framework, do not need to use it.

Windows API call. All Visual languages ​​will be used in the same language as other languages ​​for universal runtime languages ​​(CommON language runtime)

Data definition type, array, user custom array, class, and interface. But then do some sacrifices, such as fixed length strings, and

0 An array of 0 is no longer supported.

Visual Basic has now become a true object language, some inconsistent features, such as Gosub / Return statements, and Defint

Already removed from a new language.

Such a result is that Visual Basic is more energetic, making it one of the most effective tools developed based on Windows applications.

It is also the best tool for developing the next generation of Web sites.

Upgrade to Visual Basic.Net

Visual Basic.NET can make traditional Windows developers to create next-generation Web and multi-layer applications. So your code

Need to upgrade to adapt to Visual Basic.Net

After you use Visual Basic.net to open the Visual Basic 6.0 project, you can upgrade step by step through the automatic upgrade tool and create a new

Visual Basic.net project. This upgrade is one-way, both new Visual Basic.NET projects can't be in Visual Basic 6.0

turn on.

When engineering upgrades, Visual Basic.NET modifies changes in syntax and converts the Visual Basic 6.0 form to a Windows Form. In communication

Under normal circumstances, you need to do some modifications, because the automatic upgrade tool is not possible to do everything for you.

To help change the original code, when your project is upgraded, Visual Basic.net will add "Upgrade Report" in the project to list all the questions.

At the same time, add an comment in your code, you need to do this, these comments will be listed in the Task list window as the "to do" list, so you can

For a part of it, you need to change the part, you can only double-click the relevant item in the task list. Every task and upgrade

The list items in the report have related online help titles to give you more help.

Let Visual Basic 6.0 and Visual Basic.net work

Visual Basic.NET supports the upgrade of Visual Basic 6.0 generated projects, if your project is written in VB 1-5, you need to rise first

Level Visual Basic 6.0 project, compiled, and then upgrade to Visual Basic.net.

Visual Basic.Net and Visual Basic 6.0 can be installed under the same system and can be run at the same time. Similarly, use an earlier version or it

The COM components written in its language can also be integrated into the Visual Basic.net. For example, you can drag - ActiveX written in a Visual Basic 6.0

Controls to the Visual Basic.NET Windows Form, using the COM components of Visual Basic 6.0 in the class of Visual Basic.net. Components compiled by Visual Basic.net have a little different from Visual Basic 6.0, Visual Basic.NET object is passed

The garbage collection method is released, so there is a certain delay between the object being deleted to the object is truly from the release of the release.

In addition, Visual Basic.NET provides the binary compatibility between Visual Basic.Net components with Visual Basic 6.0. Expand now

Components are easier than ever, configuring a component file only requires a simple copy file to the directory (no regsvr32). Set a group

The item upgrade to the new version needs to be overwritten in the new file. What you have to do is determined that the new component is compatible with the same way.

Structure introduction

The .NET platform has improved the structure of the previous version platform, providing better support for the scalability and distribution characteristics of the application. For example, offline data access

Ask, HTTP-based messaging file configuration. To get the above features, you need to use Visual Basic.Net.

Browser-based application

Visual Basic 6.0 and Visual Studio 6 provide the following techniques to establish browser-based Internet and intranet applications:

WebClasses

DHTML Projects

ActiveX Documents

Active Server Pages (ASP)

ASP.NET is introduced in Visual Basic.NET, and ASP.NET is an enhanced version of ASP and adds to a web forms structure, Web

The form is a very important part of the .NET architecture. A web form contains two parts: HTML files and source files. HTML file for

Description page; source program file is used to respond, control the page event. Creating a web form is as simple as it is now created a VisualBasic form.

Its WysiwyG interface design is the same as the current Visual Basic. The following picture shows a design of a web form:

The web form is running on the server, generating an HTML page based on HTML3.2 standard is sent to the client. This is the same as ASP, but due to the web

The order is compilation, and the speed is much faster than explaining the ASP executed.

Below is some introduction and structural parties that are seamlessly transferred to the browser-based app development development from Visual Basic 6.0 to Visual Basic.NET.

Suggestions for face.

We recommend that you use the Microsoft multi-layer architecture to develop your application, use ASP to develop interfaces while using Visual Basic 6.0 or Visual

COM components developed by C 6.0, Visual Basic.net fully supports ASP, you can use ASP, ASP.NET, web forms simultaneously to extend your app.

At the same time, Visual Basic 6.0 or VC6 business components can be used directly in Visual Basic.net without upgrade.

The DHTML application containing the DHTML page and the client DLL cannot be automatically upgraded to Visual Basic.net. We recommend you in Visual Basic

6.0 Develop these applications. Like the DHTML project, ActiveX Documents are not supported by Visual Basic.net. Can't upgrade automatically. We built

Discuss: or develop ActiveX Documents under Visual Basic 6.0 or convert ActiveX Documents to a user-defined control. but

ActiveX Documents and DHTML applications can be integrated into Visual Basic.net technology.

Web class (WebClasses) will no longer exist in Visual Basic.NET. Web applications will be upgraded to ASP.NET; however, you still need to make some changes after the automatic upgrade. Existing web applications can be integrated into the web form and ASP applications of Visual Basic.NET, but in the new project,

We recommend using the ASP's Windows DNA platform in the new project. For more information about Windows DNA, please 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 to establish client / server applications:

Visual Basic Form

Microsoft Transaction Server (MTS) / COM Intermediate Layer

User control

Visual Basic.net provides a new form package: Windows Form. Windows Forms are different relative to Visual Basic 6.0

The object module, but most of them are compatible. When your project is upgraded, the Visual Basic Form is automatically upgraded to the Windows Form. Below is

An example of a Windows Form:

For the MTS and COM server components of the development of the intermediate layer, Visual Basic.Net provides more powerful support. Use a unified debugger,

You can go back to the client from the client to the MTS / COM component. At the same time, the integrated debugger also supports the inside of the MTS and COM components.

Debug (component needs to be compiled, including symbol debug information, and not optimized).

Visual Basic.NET also also provides a new intermediate layer component: Web Services. The web server is included in the ASP.NET,

Its structure is shown below:

The allowable method request can be passed through the firewall by using the HTTP transfer. Data transfer uses an industrial standard XML, allowing other languages ​​to

And platforms access their features. Although the MTS transaction is no longer supported, you still have reason to upgrade your app to the web server, if you don't just need

To distribute transaction processing and need cross-platform operations. You can complete with simple drag-release through Visual Basic.Net.

When your project is upgraded, the user control will be upgraded to a Windows control; however, the custom property tag settings and acceleration keys are not upgraded.

Single-layer application

Visual Basic 6.0 supports the establishment of single-layer applications for the following types:

Single layer database application

Visual Basic plugin

Ordinary applications and games.

The representative of a single layer database program is to access the Microsoft Access database using Visual Basic. These applications can be upgraded to Visual

Basic.net

Now Visual Basic.NET Integration Development Environment (IDE) has been completely integrated into part of Visual Studio.net IDE, Visual Basic.Net

Extended module containing new neutral languages ​​Visual Basic.NET is now equivalent to Visual Studio.net

Add-Ins, you can use any language in Visual Studio.NET to develop plugins. For example, you can write a Visual Basic.NET plugin

To draw the color of the Visual C # form or add a comment for the VB class. In order to support these new features, Visual Basic.net has no longer supported the old

Extended modules, you need to change the extension object in the original program.

Many programs are regulated in the application (Utility Program). The application needs to operate files and set the registry. In this regard, Visual Basic.NET also provides new features. For example, an unexpected handle can capture file system errors and use registry cates to handle registry. It should be noted that some

Depending on the program of Performance Characteristics, such as the game needs to be improved, because Visual Basic.net

For new system performance characteristics, for game development under Visual Basic.net, you can use Microsoft DirectX7, or use new GDI: GDI ,

GDI includes a lot of new features, providing an alpha mix, anti-aliasing support, and more image file formats for simple 2-D games.

Database operation

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 enhanced version of ADO, called ADO.NET. ADO.NET's goal is to operate offline data. At the same time for the distribution of ADO

Application provides more powerful support. ADO.NET provides binding databases to Windows Form Controls and web forms.

By doing some small changes, DAO, RDO, ADO can still be used in Visual Basic.net. However, Visual Basic.net does not support DAO

And the RDO database to the control, database control, or RDO user connection binding. We recommend applying the application of DAO and RDO in the application or still use

Visual Basic 6.0 is developed or upgraded to Visual Basic.NET to change them to ADO data binding.

Language improvement

We can see the C supporters in many programming forums or newsgroups to refer to VB as a toy language (Toy Language). Where VB is most

It is not really supportive to object-oriented programming (OOP).

These will become past in the new Visual Basic. Visual Basic.net will truly support OOP. Inheritance, polymorphism

(POLYMORPHISM) and overloading. Of course, it is still not allowed. Includes some new data structure, structural error control (Error

Handing) and threads. These will be supported by the new VB.

inherit

Suppose you have written a base class that contains only a function named BASECLASS:

Function getCustomername ()

'Do Some Stuff

END FUNCTION

If you want to create a new class and use the getCustomerName function in Baseclass. But I don't want to rewrite a code code. So inherit,

You can write new categories like this:

Inherits Baseclass

Function getCustomerid ()

'Do Some Stuff

END FUNCTION

Overload

The overload is the process of establishing two functions with the same name but the parameter properties. It is assumed to have a getCustomID function according to the input and output.

The ID number of the household. Then this function may have the following two types:

Function getCustomerid (CustName As String) AS Integer

'Get the user ID through the username

END FUNCTION

Function GetCustomerid (Purch As Long) AS Integer

'Get user ID according to the shopping list number

END FUNCTION

By overloading, you can call the same function according to different types of input.

In fact, the current VB provides overloaded features to some extent, considering the following functions: Function getCustomID (VIN As Variant) AS Long

GetCustomID = VIN

END FUNCTION

You can call two ways in the following

ID = getCustomID ("123")

or

ID = getCustomID (123)

So why should I introduce an overload 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 will not exist, detailed introduction to the content below the upgrade section.

Polymorphism

Polymorphisms redefine a function of a function in a class. For example, you need to build a subclass based on BaseClass classes, but it needs to be re-

Write a getCustomerName function, in the new version of VB, you can write this:

Inherits Baseclass

Function GetRDERS ()

OVERRIDES Function GetRDERS ()

...

END FUNCTION

Thread

The new Visual Basic language structure section will contain the establishment of multithreaded, and a thread is established as follows:

Set t = new thread (New ThreadStart)

(Addressof (BaseClass.Function1))

From the above example, you can see that the Addressof function in Visual Basic.NET will actually return the function of the function. This is in progress API calls,

For example, the callback function will be very helpful.

Error Handling

Another big improvement in Visual Basic.Net is the error handling. Visual Basic will provide try ... catch ... finally structure, just like

Same in Delphi (Microsoft's original: Just Like Those "respectable" languages ​​:-)). E.g:

Sub SafeWrite ()

Try

Open "testfile"

...

Write # 1

Catch

Kill "Testfile"

Finally

Close # 1

END TRY

End Sub

upgrade

After the code upgrade, Visual Basic.Net creates a new upgrade project. By following the following examples, your code has been upgraded.

Variant type to Object type

Previous version of Visual Basic support VARIANT data

转载请注明原文地址:https://www.9cbs.com/read-1778.html

New Post(0)