Prepare your Visual Basic 6.0 app for updating to Visual Basic.net
Microsoft Company Over the October 2000: This article provides some suggestions for Microsoft Visual Basic developers who update their applications to Visual Basic.net. It includes some information about the Visual Basic.NET update tool and discusses the overall structural guiding ideology that makes the application updated from Visual Basic 6 to Visual Basic.NET. Directory ???? Overview
??? What is Visual Basic.net?
??? Why is Visual Basic.net not 100% compatible?
??? Update to Visual Basic.net
??? Use Visual Basic 6.0 and Visual Basic.Net at the same time.
??? system structure recommended
??????? Based on the browser-based application
??????? client / server project
??????? single layer application
??????? data
??? Update
??????? variant to the object
??????? integer to short integer
??????? characteristic syntax
??????? Visual Basic form to Windows Form
??????? interface
??? Update reports and comments
?? Programmed suggestions
??????? Application early binding
??????? Use Date to store the date
??????? Solve the problem of never-termization provision
??????? Avoid NULL spread
??????? use 0 border arrays
??????? Use constants to replace the potential value
??????? Use array and fixed length strings in the custom type
??????? Avoid inheritance characteristics
??????? Windows APIS
??????? For the considering of the form and control
Overview This article is to provide some suggestions for users who prepare to update Visual Basic to Visual Basic.net. Visual Basic.net will open and update the Visual Basic 6.0 project to Visual Basic.net technology, but in most cases, you must do some modifications before you transfer Visual Basic 6.0 projects. The purpose of this article is to suggest you how to design and implement your existing Visual Basic project, making you minimize modifications you need to do when you update to Visual Basic.NET, in the most suitable place to use new language structure; however Articles are not a reference book for Visual Basic.NET languages. Note: Visual Basic.net is still developed; some compatibility details may change before product release. Follow these guiding principles and cannot guarantee that your code no longer needs to be modified; the purpose of this guidance is to reduce the workload of this transformation. The Update Wizard and Command Line Update Tools in Visual Basic.NET are still in the early development phase, so their functions are limited. The purpose of these features in beta is to let you know how the update process works, see how to modify VB6.0 code so they can work in Visual Basic.net; in the beta1 version, most actual projects may be It cannot be successfully transplanted. What is Visual Basic.Net? Visual Basic.net is the next version of Visual Basic. Microsoft is not simple to add some new features on the basis of Visual Basic 6.0, but re-replaced this product, making the written distributed application, such as web pages and enterprise N-layer systems, more simpler than before. Visual Basic.Net has two new form packs (Windows Forms and web forms); a new ADO version for non-connection data sources; improved languages, to inherit keywords, enhance type security The low-level structure that senior developers need. These new features open new portals for Visual Basic developers; use web forms and ado.net, you can now quickly develop scalable websites; use inheritance, this language now really supports object-oriented programming; Windows Form Natural Support accessibility and visual inheritance feature; now deploying your application is very simple, just copy the executable from a directory to another. Visual Basic.net has now fully integrated with several languages in Microsoft Visual Studio.net. Not only can you develop application components in different programming languages, but now your class uses cross-language inheritance to inherit from a class written in other languages. Using a unified debugger, you can now debug multilingual applications, regardless of whether they are running on the local machine or on a remote computer. Finally, no matter what language you use, Microsoft .NET framework provides a rich API interface function for Microsoft Windows and Internet. Why is Visual Basic.net not 100% compatible? Two options - refurbished source code based on the design of Visual Basic.NET makes it on the .NET framework, or make full use of the platform from the basis. In order to deliver the most important features (for example: inheritance, thread, etc.), in order to provide a complete unlimited access platform, in order to enable Visual Basic to enter the next generation of web applications, the correct decision is: Creating a new platform from the basis. For example, a new feature of most Windows Forms can be added to an existing base code as a new control and more attributes.
However, this cost is to abandon other more features inherited to the Windows form, such as: security, visual inheritance characteristics, etc. One of our most important purposes is to ensure that the Visual Basic code is fully interacting with other languages, such as Microsoft Visual C # or Microsoft Visual C , so that Visual Basic developers can simply use the function of .NET Framework, not to help Traditional needs to process the programming environment for Windows API functions. Visual Basic has the same variable type, array, user-defined type, class, class, class, class, class, class, class, class, and interface of Visual C and other languages. It has to go to some characteristics, such as fixed length characters. Strings and non-zero addresses, etc. Visual Basic is now a real object-oriented language; some non-intuitive and inconsistent features such as gosub / return and defint have been out of this language. The result is a reinforced Visual Basic, which continues to develop Windows-based applications, and is now positioned to create the best tools for the next generation website. Update to Visual Basic.net Visual Basic.net completes a major change in traditional Windows to create a next-generation web page and N-layer applications. For this reason, your code needs to be updated to make full use of Visual Basic.net. When you open a Visual Basic 6.0 project in Visual Basic 6.0, this process is automatically executed: Update Wizard Step by Step You Boots You Complete Update Process and build a new Visual Basic.net project (your original project is still in good condition) . This is a one-way process; Visual Basic.NET project cannot be opened in Visual Basic 6.0. When your project is updated, since some grammar changes will modify the code and the Visual Basic 6.0 form is Windows Form. In most cases, you must make some modifications to your code after the update. This is because an object and language characteristics in automatic update are in Visual Basic.Net, there is too much difference in the equivalent, or the equivalent. After updating, you will also want to better use some of the new features of Visual Basic.Net by changing your app. For example: Windows Forms Support Controls, so you can remove forms in Visual Basic 6.0 to reprogram the VB.NET Support Control After your project is updated, in order to help you do these modifications, Visual Basic. NET adds a "update report" to your project, in detail each problem, and insert a comment in your code, prompt you to prompting these code to modify. Since these comments are displayed in the new task list window, you can easily see which needs to be modified and you can easily find the relevant code by double-click task. Each task and projects in the update report are connected to the online help, the relevant topics will give you such as why this code needs to be modified, what you need to do, etc. Further guidance. Follow this article, you can make your project minimize the work you need to do after updating to Visual Basic.net, and in some cases, you can even eliminate this necessary modification.
In most cases, this recommendation also represents a good programming habit; however, we also realize that there is no equivalent in Visual Basic.NET. If you want to update your project to Visual Basic.net, you will You must use them less. Simultaneously use Visual Basic 6.0 and Visual Basic.Net Visual Basic.Net to support updated Visual Basic 6.0 projects; if your project is Visual Basic1-5 version, we recommend that you are first loaded into Visual before updating to Visual Basic.net. Basic6.0 (select Update Microsoft ActiveX Control), compile and save. Visual Basic.net and Visual Basic 6.0 are installed on a computer and can run at the same time. Similarly, programs written in Visual Basic.Net and Visual Basic 6.0 can also be installed simultaneously on the same computer. Components written in Visual Basic.NET can be used with Visual Basic's early versions or other language COM components. For example, you can put an ActiveX control written in a Visual Basic 6.0 on the Visual Basic.Net Windows Form, you can use the Visual Basic 6.0 COM object from the Visual Basic.Net class library, or will use a Visual Basic.net library. Connections Add to the executable of Visual Basic 6.0. Components compiled with Visual Basic.Net and compile with Visual Basic 6.0 have some subtle differences at runtime, because Visual Basic.NET object release is completed by debris, when the object is clearly destroyed, in memory There is a delay before completely deleting. There are also some changes such as variants and objects will be described later in this article. These differences in combination are the Visual Basic.Net application has similarity to the Visual Basic 6.0 application but is not exactly the same at runtime. In addition, Visual Basic.NET makes it unnecessary between binary compatibility between Visual Basic.Net components and Visual Basic 6.0 components. Now the components already have a more robust version and development system than before. The deployment of files can be made in a simple copy to the directory (and no longer use regsvr32), the component update to a new version is as simple as a new file instead of an old file. What you have to do is to ensure that classes and methods are compatible with the previous versions. The architecture recommended .NET platform improves the previous architecture, a large number of support for distributed applications accessed by discrete data, based on HTTP-based information transfer and file copy-based configuration (no longer registration components) stand by. To make full use of these features, you should design your app with the structure similar to the structure used in Visual Basic.NET. Based on browser-based application
Visual Basic 6.0 and Microsoft Visual Studio 6.0 provide several techniques to create a browser-based Internet and internal network applications:
Web Page DHML Project ActiveX Document Activity Server Page (ASP)
Visual Basic.net introduces ASP.NET, which is an enhanced version of ASP and adds a web form in the structure, which is an HTML page with Visual Basic events. This architecture is based on a server.
The following is a series of development Visual Basic 6.0 Browser applications (these applications can be seamlessly combined with Visual Basic.Net projects) recommendations.
We use Microsoft Intermediate Architecture Guidelines to create your application, create an ASP interface, and use Visual Basic 6.0 or Visual C 6.0 COM object to form your business logic. ASP is fully supported in Visual Basic.net, and you can continue to use ASP and ASP.NET to extend your application and web forms. Visual Basic 6.0 and Visual C 6.0 enterprise objects can be used without modifying or updating to Visual Studio.net. DHTML application package DHTML page and client DLL. This application cannot be automatically updated to Visual Basic.net. We recommend that you don't have to update this type of application, continue to stay in Visual Basic 6.0. The ActiveX document is also unsupported in Visual Basic.net, just like the DHTML project, is not automatically updated. We recommend that you either need to update this type of application, continue in Visual Basic 6.0, or if you might use the user control instead of the ActiveX document. Visual Basic 6.0 ActiveX documentation and DHTML applications can interact with Visual Basic.NET technology. For example, you can via Visual Basic.NET web form to Visual Basic 6.0's DHTML webpage, and vice versa. The web page is no longer existed in Visual Basic.net. The application of the web page class will be updated to the ASP.NET; however, you will have to make some necessary modifications after the update. Existing web page applications are interacting with Visual Basic.net web forms and ASP applications, but for a new project, we recommend that you use ASP's Windows DNA platform and Visual Basic 6.0 corporate object. Want to know more about the use of Microsoft Intermediate Architecture to create applications, see Microsoft Windows DNA website.
Customer / server project
Visual Basic 6.0 provides several technologies to create a client / server application:
Visual Basic Forms Microsoft Transaction Server (MTS) / COM Neural Object User Controls
In Visual Basic.NET, there is a new social form package: Windows form. The Windows Form has a different object model that is different from the Visual Basic 6.0 form, but is roughly compatible. The Visual Basic form is converted to a Windows Form when your project is updated.
Visual Basic.NET improves support for the development intermediate layer MTS and COM component service components. Using a unified debugger, you can enter the MTS / COM component from the client application and return to the client. You can also enter the Basic 6.0 MTS / COM component by using a unified debugger (if they make local code and symbol debug information and non-optimized compiler).
Visual Basic.Net also introduces an intermediate component: web service. The web service is sent in the ASP.NET and allows the method to request a firewall by using the HTTP transfer. They pass the industrial standard XML, return data, allow other languages and other platforms to access their functions. Although they don't support MTS transmission, you can change your MTS / COM component to web services when you don't need distributed processing but want to interact with other platforms. Although there is no automatic method for him, this task is simple, and it can be done in a few minutes after updating to Visual Basic.net.
When your project is updated, the user control is updated to the Windows control; however, custom property label settings and acceleration key assignments cannot be updated.
Single-layer application
Visual Basic 6.0 Supports Creating a variety of single-layer applications: single-layer database application Visual Basic plug-in application and game software
Single-layer database applications typically store data in the Visual Basic application in the Microsoft Access database. These applications have to update to Visual Basic.net has some limitations (see section subsequent data chapter).
Since the Visual Basic.NET integration development environment is fully integrated in the Visual Studio.net integration development environment, Visual Basic.NET has a new language-neutral extension module. The Visual Basic.NET plugin is now a Visual Studio.NET plugin, which you can automatically add some features to any language in Visual Studio.net. For example, you can write a Visual Basic.NET plugin, which is completed in Visual C # or adds a comment to the Visual Basic class in Visual C #. In order to add this function, Visual Basic.net abandoned the extensible module that you would need to change the scalable object in your application to make full use of these new features.
Many applications can be classified into the utility class. Practical application processing files, set registry, etc., and often do not need additional changes. After updating, you can make full use of many new features, such as in addition to the exceptions in the language to capture file system errors, using the .NET Framework Registration class to operate the registry. We should realize applications that depend on Visual Basic 6.0 special run feature, such as entertainment games, may need some modifications because Visual Basic.Net has different operating features. Support for games in Visual Basic.Net, allows you to use Microsoft DirectX 7 or GDI new version. GDI introduces many new features, including Alpha binding to 2-D graphics support both the researcher and support for impression file format.
data
Visual Basic 6.0 provides several data access types:
ActiveX (ADO) Data Object Remote Data Object (RDO) Data Access Object (DAO)
Visual Basic.net introduces enhanced ADO versions called ADO.NET. ADO.NET positions the target in discrete data and provides improved ADOs in a distributed application. ADO.NET provides read and write data binding for Windows Forms, providing read-only data binding for web forms.
DAO, RDO, and ADO have been slightly modified in the code of Visual Basic.NET (this article will be mentioned later in the language chapter). However, DAO and RDO are not supported in Visual Basic.NET to bind data to controls, data controls, or RDO users. We recommend that if your application includes RDO and DAO data binding controls, you either update to update to DAO and RDO data bind to ADO before updating to Visual Basic.net, because ADO data is bound to Windows Windows The body supports ADO data binding. For how to do, please refer to the help file of Visual Basic 6.0.
In summary, we recommend using ADO in Visual Basic 6.0 projects.
Update
When your code is updated, Visual Basic.Net produces an updated project and a change in the necessary language and objects. In the following sections, some examples are provided, explaining how to update your code.
Variant to the object
Support Variant's data types in the early versions of Visual Basic, which can be assigned to any type (except for the fixed length string), an empty string, zero and null. In Visual Basic.net, the function of variants and objects For a new data type: object. Object Data Type Allocation Simple Data Types, Empty Data, None, and NULL, and even a pointer to the object. When your project is updated to Visual Basic.NET, all the variables for Variant changes to objects, and when the code is inserted into the editor, the keyword Variant is replaced by Object.
Integer to short integer
In Visual Basic.NET, 16-bit numbers are now a short (short integer), and 32 is the number (integer) (64 bit becomes long (long integer). When your project is updated, These data types have changed.
DIM X as integer
DIM Y As Long
Updated to:
DIM X as Short
DIM Y AS Integer
Property syntax
Visual Basic.NET introduces more intuitive syntax for properties, which is Get and Set classes. Your property description update is as follows:
Property Get MyProperty () AS INTEGER
MyProperty = m_myproperty
End Property
Property Let MyProperty (NewValue AS Integer)
m_myproperty = newValue
End Property
Updated to:
Property MyProperty () AS Short
Get
MyProperty = m_myproperty
END GET
Set
M_myProperty = Value
End set
End Property
Visual Basic Form to Windows Form
Visual Basic.Net has a new form package, a Windows form, which naturally supports access feature and has a local menu editor. Your Visual Basic Form will be updated to a Windows Form.
Figure 2. Menu editor placed on the Windows Form (click on the picture to see a larger image)
interface
In the earlier versions of Visual Basic, the interface of the public class is usually invisible to the user. In Visual Basic.net, you can view and edit it in the code editor. When your project is updated, you can choose whether to automatically generate an interface declaration for your public class.
Update reports and comments
After your project is updated, an updated report is added in your project, and the place where you need to modify in your updated code. In addition, the annotations joined in your code warns some potential issues. These comments are listed in the task list of Visual Studio.net.
Figure 2. Menu editor placed on the Windows Form (click on the picture to see a larger image)
interface
In the earlier versions of Visual Basic, the interface of the public class is usually invisible to the user. In Visual Basic.net, you can view and edit it in the code editor. When your project is updated, you can choose whether to automatically generate an interface declaration for your public class.
Update reports and comments
After your project is updated, an updated report is added in your project, and the place where you need to modify in your updated code. In addition, the annotations joined in your code warns some potential issues. These comments are listed in the task list of Visual Studio.net. Figure 3. Increases the update annotation in the Visual Basic code, also added in the list of tasks
Program suggestion
In this section, how to write code to make some suggestions for your project update to Visual Basic.NET.
Early binding
Visual Basic 6.0 and Visual Basic.net support advanced binding objects, which actually declares a variable as an Object data type, and then assign an instance to it at runtime. However, during the update process, it will introduce some problems when parsing the default attribute or changing and attribute, method, and events in the underlying object module. For example, if you have a form FORM1 with label Lable1, the following Visual Basic 6.0 code sets the label to "sylext":
DIM O as Object
Set o = me.label1
o.caption = "sylext"
In the Visual Basic.Net Windows form, the CAPTION attribute of the Label control is now called Text. When your code is updated, all instances of the CAPTION attribute will be transformed into text, but due to the type of object of the late binding object, even if some features can be translated, Visual Basic cannot detect the type of object. In this case, you should modify the code after the code update is complete.
If you use an early binding object to reply the code, it will automatically update:
Dim o as label
Set o = me.label1
o.caption = "sylext"
You should declare any suitable object type variables in a possible place, not a simple life-based object (Object) data type.
When you use objects and variant variables in your Visual Basic 6.0 code, when you assign variables, perform a variable to a variable or to a function, we recommend using a clear transformation. For example, the purpose of the ' ' operator is not very direct in the following code:
DIM VAR1 AS VARIANT
DIM VAR2 As Variant
DIM VAR3 AS VARIANT
Var1 = "3"
VAR2 = 4
Var3 = var1 var2 'unclear: What is the intention?
VAR1 and var2 are added as a string, or is it integrated?
The above example may generate an operation error in Visual Basic.NET. Use it to clearly convert the last line of code to ensure the work:
VAR3 = CINT (var1) cint (var2) 'good: Explicit Conversion
Visual Basic.NET supports the overloaded function based on parameter type. E.g:
Environ (Expression As Integer) AS String
ENVIRON (Expression As String) AS String
Visual Basic.net determines which function called according to the parameter. If you pass an integer parameter to environ (), you will call the integer version of the function; if you pass the string, call the string version of the function. Pass variants or object data types may cause compilation or run errors to overload functions. Use direct transformation, as follows, after your code is updated, working properly in Visual Basic.net. Dim a as string
DIM V As Variant
v = "pat"
A = environ (cstr (v)) 'good: Explicit Conversion
It is a good programming habit to explicitly convert advanced binding objects. This makes it easy to judge the purpose of the code, and it is easy to enable your code into the Visual Basic.net.
Use Date Storage Date
Early versions of Visual Basic support to store and process the date using the Double data type. You should not do this in Visual Basic.net, because the data cannot be stored as Double. For example, the following code is valid in Visual Basic 6.0, but in Visual Basic.net may cause compilation errors.
DIM DBL AS DOUBLE
DIM DAT AS DATE
DAT = now
DBL = DAT 'VB.NET: Double Can't Be Assigned to a Date
DBL = DateAdd ("D", 1, DBL) 'VB.NET: can't Use Double In Date Functions
DAT = CDATE (DBL) 'VB.NET: cdate can't Convert Double To Date
The .NET platform provides Tooadate and fromoadate functions to complete the transformation between dual precision data and date data. However, when your project is updated to Visual Basic.NET, it is very difficult to determine the meaning of codes that use dual precision data to store the date. To avoid modifying your code in Visual Basic.net, use the date type data type to store the date.
Handling free-censorship
In Visual Basic 6.0, many objects show the default feature, omitting them in programming, is a programming shortcut. For example, TextBox has a default feature Text, so the default write:
Msgbox form1.text1.text
You can use a simple method:
MSGBOX FORM1.TEXT1
The determination of the default attribute is done when the code is compiled. In addition, you can use the default attributes of advanced binding objects as follows:
DIM OBJ AS Object
Set obj = form1.text1
Msgbox Obj
In the late binding example, the default attribute is determined at runtime, and the value of the default attribute of the MSGBox displayed by the MSGBox is Text1.
Visual Basic.NET does not support no provincial properties, which do not support this programming shortcut. When your project is updated, Visual Basic.NET parses these unparalleled provincial properties, but the advanced binding controls that can be parsed at runtime cannot be automatically parsed. In these cases, you will have to modify the code yourself. What is more trouble is that many libraries use _default to achieve default properties. _Default is like an agent that is transferred to a real default attribute. So, when your item is updated, some default properties will be solved by _default. These codes can work normally, but this is not as understood to directly use the actual properties. For these reasons, we should try to avoid using no free groups in Visual Basic 6.0. Written as: DIM OBJ AS Object
Set obj = me.text1
MSGBOX Obj 'Relying On Default Property
MsgBox Me.Text1 'Relying On Default Property
Use directly:
DIM OBJ AS Object
Set obj = me.text1
Msgbox Obj.text 'Good: Default Property Is Resolved
MsgBox Me.Text1.text 'Good: Default Property Is Resolved
In Visual Basic.NET does not support no provincial properties, but supports the provincial properties. In order to understand the differences of these two types, it is considered that the default attributes with parameters always have an index. Below is the default attribute of ADO Recordset: an example of a Fields set. Code:
DIM RS as adodb.recordset
RS ("CompanyName") = "somecompany"
RS! companyName = "somecompany"
A simple writing method of the following code:
DIM RS as adodb.recordset
Rs.fields ("CompanyName"). Value = "SomeCompany"
rs.fields! companyName.Value = "somecompany"
In this case, the Fields property is parameter, so this usage is valid in Visual Basic.net. However, the default attribute of Fields is Value is no, so the correct usage in Visual Basic.net is:
DIM RS as adodb.recordset
RS ("CompanyName"). Value = "SomeCompany"
rs! companyName.value = "somecompany"
This example and most other default attributes are determined when your project is updated, so a good program habit is to analyze in Visual Basic 6.0. However, you should avoid using the object object and variant Variant data type default properties because they can't be parsed in your update project, and you need you to modify the code.
Avoid the transfer of NULL
Earlier Version of Visual Basic supports NULL delivery. NULL Pass Support This assumption: When Null is used in a certain expression, the result of this expression is NULL yourself. All result V is NULL in the examples below.
DIM V
V = 1 NULL
V = NULL RIGHT $ ("Sometext", 1) v = Right ("Sylext", 0)
NULL is not supported in Visual Basic.net. 1 NULL in Visual Basic.NET will generate an error that does not match. In addition, when Visual Basic 6.0 has two versions of Left function -left $ returns a string, left returns a variant, it may be null - only one version of the version of the Visual Basic.net, it always returns A string.
To be compatible in Visual Basic 6.0 and Visual Basic.NET, you should always test NULL instead of relying on NULL delivery.
NULL is often used in database applications, then you need to test whether the fields of the database contain NULL. In this case, you should use the function isnull () to test the results and perform the appropriate operation.
A related problem involves connecting a string with null. When programming the database object, connect a null string to the field to ensure that NULL's value is forced to be empty strings, which is very common. E.g:
MyString = RS! Field1 & ""
This technology is also in Visual Basic.net