Migrate your Visual Basic 6.0 to Visual Basic.Net

zhaozj2021-02-08  288

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. In the article, the new features of Visual Basic.Net, the introduction of the upgrade tool information, and the guide to the Visual Basic 6 Structure to Visual Basic.net

What is Visual Basic.NET? Why is Visual Basic.net not provide 100% compatible? Upgrade to Visual Basic.net works in Visual Basic 6.0 and Visual Basic.NET

The basic structure introduces the improvement in the browser-based program server / customer engineering single-layer application data language

Upgrade Variant to Object Integer to Short Property Syntax Visual Basic Forms to Windows Forms

Upgrade Report Note Note Programming Introduction The BOOLEAN Data Type of the BOULAN Data Types using the pre-bound binding data is used to avoid NULL propagation use 0 lower bound arrays and does not use the value of the value user custom type. Arranges and fixed-length strings Avoid genetic action Windows API calls to forms and controls

Overview: This article recommends to Visual Basic developers who are ready to transplant their applications to Visual Basic.NET. In the article, the introduction of the Visual Basic.NET upgrade tool and the guidance of smoothing the Visual Basic 6 Structure to Visual Basic.NET is automatically upgraded when Visual Basic 6.0 project is opened, but in most cases You need to do some changes to the Visual Basic 6.0 program opened under Visual Basic.net. The purpose of this article is that your changes in the original procedure are as small as possible and effective. Note: Visual Basic.net is still in development, so some details below may change, the following instructions do not guarantee that the post-production process does not need to be changed.

What is Visual Basic.net? Visual Basic.net is the next generation of Visual Basic. It is not simple in Visual Basic 6.0 that adds some new features, 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 languages, remove the original keywords, improve Type data security and Provide a low-level structure to meet the needs of high-level developers. These new features provide new development windows for Visual Basic developers: You can quickly develop scalable Web sites through web forms and ado.net; through inheritance, this language implements real support object-oriented programming (Object -oriented programming; Windows form itself 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 develop components in different languages, but also to derive another language from a language written in a language by cross-language. Written class.

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. The correct choice 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 sacrifice a lot of intrinsic features of new Windows forms, such as security, and visual inheritance.

An important goal is to make the Visual Basic code can be 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 use the function of the .NET framework without the need to use the Windows API call. All Visual Languages ​​will use the same data definition type, array, user-defined array, class, and interface with other languages ​​for universal runtime language (CommON language runtime). However, this is to do some sacrifices, such as fixed length strings, and arrays that are not 0 as the lower bound will no longer be supported.

Visual Basic has now become a true object language, some inconsistent features, such as gosub / return statements, and Defint have been removed from a new language. The result is that Visual Basic is more energetic to make one of the most effective tools developed based on Windows applications, and is also the best tool for developing the next generation of Web sites.

Upgrading to Visual Basic.Net Visual Basic.NET can make traditional Windows developers to create next-generation Web and multi-layer applications. So, your code needs to be upgraded to adapt to Visual Basic.net After you open the Visual Basic 6.0 project using Visual Basic.Net, you can upgrade and create a new Visual Basic.NET through the Automatic Upgrade tool. This upgrade is one-way, both new Visual Basic.NET projects that cannot be opened in Visual Basic 6.0. When engineering upgrades, Visual Basic.NET modifies changes in syntax and converts the Visual Basic 6.0 form to a Windows Form. Under normal circumstances, you also 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, and add a comment in the code prompting you to do, these comments will be " To do "lists are listed in the task list window, so you can easily need to change the part. To browse the relevant code, you only need to double-click the relevant item in the task list. Each task and the list items in the upgrade report have related online help titles to give you more help.

Let Visual Basic 6.0 and Visual Basic.NET work Visual Basic.NET support upgrade Visual Basic 6.0 generated project, if your project is written in VB 1-5, you need to upgrade the road Visual Basic 6.0 project, compile, After saving, 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, the COM components written in earlier versions or other languages ​​can also be integrated into the Visual Basic.net. For example, you can drag - A Visual Basic 6.0 written ActiveX control to the Visual Basic.NET Windows Form, using the COM component of Visual Basic 6.0 in the class of Visual Basic.net. Visual Basic.NET compiled components with the components compiled by Visual Basic 6.0 a little bit, and the Visual Basic.NET object is released through the garbage collection method, so the object is deleted to the object is really released from memory. Have a certain delay. In addition, Visual Basic.NET provides the binary compatibility between Visual Basic.Net components with Visual Basic 6.0. Now expanding a component is more easier than ever, configuring a component file only requires a simple copy file to the directory (no regsvr32). Upgrading the components to the new version. You can use the new file override. What you have to do is determined that the new component is compatible with the same way. Structure introduction .NET platform improves the structure of the previous version platform, providing better support for the scalability and distribution characteristics of the application. For example, offline data access, HTTP-based messaging file configuration. To get the above features, you need to use Visual Basic.Net.

Browser-based Applications Visual Basic 6.0 and Visual Studio 6 provide the following techniques to establish browser-based Internet and intranet applications: WebClasSASDHTML ProjectsActiveX DocumentsActive Server Pages (ASP)

ASP.NET is introduced in Visual Basic.NET, ASP.NET is an enhanced version of ASP and adds a web form for a web form. The web form is very important in an integral part of the .NET architecture. A web form contains two parts: HTML files and source files. The HTML file is used to describe the page; the 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 picture below shows a design of a web form: (additional picture webforms1.gif)

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 the ASP, but since the web program is compiled, it is much faster than the ASP executed.

Below is some introductions and structural recommendations for 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 interfaces, using the COM components developed by Visual Basic 6.0 or Visual C 6.0, Visual Basic.net fully supports ASP, you can use ASP, ASP. NET, web forms 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 that you develop these applications in Visual Basic 6.0. Like the DHTML project, ActiveX Documents are not supported by Visual Basic.net. Can't upgrade automatically. We recommend: or develop ActiveX Documents under Visual Basic 6.0 or convert ActiveX Documents to user-defined controls. However, 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 Visual Basic.NET web forms and ASP applications, but in the new project, we recommend using ASP's Windows DNA platform in new projects. 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 Forms Microsoft Transaction Server (MTS) / COM Intermediate Layer Object User Control

Visual Basic.net provides a new form package: Windows Form. The Windows Forms use different object modules relative to Visual Basic 6.0, but most of them are compatible. When your project is upgraded, the Visual Basic Form is automatically upgraded to the Windows Form. The following is an example of a Windows form: (Additional image WindowsForms1.gif)

For the MTS and COM server components of the development of the intermediate layer, Visual Basic.Net provides more powerful support. Using a unified debugger, you can step up from the client to the MTS / COM component to the client. At the same time, the integrated debugger also supports debugging inside the MTS and COM components (components need to be compiled, including symbol debug information, and not optimization).

Visual Basic.NET also also provides a new intermediate layer component: Web Services. The web server is included in the ASP.NET, and its structure is shown below: (Additional Picture WebServices.gif)

The allowable method request can be passed through the firewall by using the HTTP transfer. Data transfer uses an industrial standard-based XML, allowing other languages ​​and platforms to 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 need to distribute transaction processing but also a cross-platform operation. 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 Applications Visual Basic 6.0 supports the establishment of the following types of single-layer applications: Single-layer database application Visual Basic plug-in normal 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 restricted to Visual Basic.NET Now Visual Basic.NET Integration Development Environment (IDE) has been fully integrated into part of Visual Studio.net IDE, Visual Basic.net contains new neutral languages ​​(Language-neutral) Extended Module Visual Basic.NET Plugin 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. To support these new features, Visual Basic.net no longer supports old extension 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 programs that depend on system performance characteristics (Performance Characteristics), such as the game needs to be improved, because Visual Basic.net provides new system performance characteristics, developing game development under Visual Basic.net, you can use Microsoft DirectX7, or using new GDI: GDI , GDI contains many new features, providing 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: 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, the distribution application of ADO 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 RDO databases to control, database controls, or RDO user connections. We recommend that it contains DAO and RDO applications or still use Visual Basic 6.0 development or upgrade to Visual Basic.NET to change them to ADO data binding.

Language Improvements We can see the C advocate in many programming forums or newsgroups to call VB as a toy language (Toy Language). Where VB is most ill, it does not really support object-oriented programming (OOP). These will become past in the new Visual Basic. Visual Basic.net will truly support OOP. Inheritance, Polymorphism and Overloading. Of course, it is still not allowed. Includes some new data structures, structural error control (error handing), and threads. These will be supported by the new VB.

Inherit assumptions you have written a basic class that only contains 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 by inheritance, you can write new categories like this: Inherits Baseclass

Function getcustomerid () 'do some stuff end function

The overloaded overload is the process of establishing two functions that have the same name but the parameter properties. It is assumed to have a getCustomID function according to the ID number of the input user. Then this function may have the following two types:

Function getCustomerid (CustName As String) AS Integer 'Get User Idend Function by Username

Function GetCustomerid (Purch As Long) AS INTEGER 'NOSCE NOTE

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 = VINEND 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 new Visual Basic introduces new features: Default TypeTy. In Visual Basic.net, the Variant type will not exist, detailed introduction to the content below the upgrade section.

Polymorphisms redefine a function of a function in a class. For example, you need to build a subclass based on the Baseclass class, but you need to rewrite the getCustomerName function. In the new version of VB, you can write this:

Inherits Baseclass

Function getorders () Overrides function getorders () ... END FUNCTION

Thread New Visual Basic Language Structure section will contain a multi-thread, 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 will be helpful in performing API calls, such as callback functions.

Error Handling Visual Basic.NET is another big improvement is an error handling. Visual Basic will provide the Try ... catch ... Finally structure, just like Delphi (Microsoft's original: Just Like those "respectable" languages ​​:-)). E.g:

Sub SafeWrite () Try Open "Testfile" ... Write # 1catch kill "testfile" Finally Close # 1END TRYEND SUB

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

Variant Type to Object Type Previous Visual Basic support Variant data type, which can be set to any raw data type and EMPTY, ERROR, NOTHING, and NULL in addition to fixed level strings. In Visual Basic.net, the Object data type can be set to any raw data type and Empty, Error, Nothing, NULL, and object pointers. When your project is upgraded to Visual Basic.net, any Variant definition will change to Object. Similarly, when you insert code in the editor, the Variant keyword will be replaced with Object. Integer Data Type to Short Data Type In Visual Basic 6.0, 16bit is now called Short. The 32bit number is called Integer (64bit number is called long). When the project is upgraded, the data definition will be changed as follows:

DIM X AS INTEGERDIM Y AS LONG Change to:

DIM X As Shortdim y as integer

Property Syntax Visual Basic.net is more intuitive for syntax for custom properties, and combines GET and SET. For example, the original attribute is as follows:

Property Get MyProperty () AS Integer M_MyProperty = MyPropertynd PropertyProperty Let MyProperty (NewValue A

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

New Post(0)