Vb. NET language improvements (rotation)

Source: Internet
Author: User
Tags definition contains data structures empty error handling inheritance integer thread
We can see in many programming forums or newsgroups that C + + advocates refer to VB as a toy language (Toy Language). One of VB's most criticized is that it does not really support object-oriented programming (OOP).
In the new Visual Basic, these will be the past. Visual Basic.NET will really support OOP. Inheritance (inheritance), polymorphism (polymorphism), and overloads (overloading). Of course, that's more than that. Includes new data structures, structural error control (handing), and threading. These will be supported by the new VB.

Inherited
Let's say you wrote a basic baseclass with a name that contains only one function
Class:

Function Getcustomername ()
' Do some stuff
End Function

If you want to create a new class and use the Getcustomername in BaseClass
Function. But there is no need to rewrite a code. So by inheriting, you can write a new class like this:

Inherits BaseClass

Function Getcustomerid ()
' Do some stuff
End Function

Overload
Overloading is the creation of two of functions with the same name but with different parameter attributes.
Ride. Suppose there is a getcustomid function that outputs the ID number of the user according to the input. Then the function may have the following two types:

Function Getcustomerid (CustName as String) as Integer
' Get user ID from user name
End Function

Function Getcustomerid (Purch as Long) as Integer
' Get the user ID from the shopping list number
End Function

By overloading, you can invoke the same function based on different types of input.
In fact, now VB to some extent provides the function of overloading, consider the following function:

Function Getcustomid (VIN as Variant) as Long
Getcustomid = VIN
End Function

You can call it in the following two ways

ID = Getcustomid ("123")
Or
ID = Getcustomid (123)

So why do you want to introduce overloads into the new version? This is because the new visual
Basic introduces a new feature: type safety (default type safety). In Visual Basic.NET, the variant type will no longer exist, as detailed in the following sections on the upgrade.

Polymorphic
Polymorphism is the process of redefining a function in a class. For example you need to build a
A subclass based on the BaseClass class, but also need to rewrite the Getcustomername function, in the new version of VB, you can write:

Inherits BaseClass

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

Thread
The new Visual Basic Language Architecture section will contain the creation of multiple threads, a line Chengjian
The following are examples of the legislation:

Set t = new Thread (new ThreadStart
(AddressOf (Baseclass.function1))

As you can see from the example above, the AddressOf letter in Visual Basic.NET
Number will actually return the pointer to the function. This can be helpful in making API calls, such as callback functions.

Fault handling (Error handling)
Another big improvement in Visual Basic.NET is error handling. Visual
Basic will provide the try...catch...finally structure, as in Delphi (Microsoft's original text is: Just like those "respectable" languages:-)). For example:

Sub Safewrite ()
Try
Open "Testfile"
...
Write #1
Catch
Kill "Testfile"
Finally
Close #1
End Try
End Sub


Upgrade
When the code is upgraded, Visual Basic.NET creates a new upgrade project. Under
Face through a few examples to illustrate your code has done those upgrades

Variant type to object type
Previous versions of Visual Basic support Variant data types that can be set
is set to any raw data type and empty,error,nothing and null except for the fixed-degree string. In Visual Basic.NET, the Object
The data type can be set to any original data type and empty,
Error,nothing,null and object pointers. When your project is upgraded to visual
After Basic.NET, any variant definition is changed to object.
Similarly, when you insert code into the editor, the VARIANT keyword is also replaced with the
Object.

Integer data type to short data type
In Visual Basic 6.0, the 16bit number is now called short. 32bit number is called
The Integer (64bit number is called long). When the project is upgraded, the data definition changes as follows:

Dim x as Integer
Dim y As Long
Change to:

Dim x as Short
Dim y As Integer

property syntax
Visual Basic.NET more intuitive changes to the syntax of custom attributes,
Combine get and set in a merged. For example, the original properties are as follows:

Property Get MyProperty () as Integer
M_myproperty = MyProperty
End Property
Property Let MyProperty (NewValue as Integer)
M_myproperty = newvalue
End Property

Change after upgrade to:

Property MyProperty () as Short
Get
M_myproperty = MyProperty
End Get
Set
M_myproperty = Value
End Set
End Property

VB forms to Windows Forms
Visual Basic.NET contains new form packages, Windows Forms, Windows Forms
Contains the built-in menu editor. Your VB window experience to upgrade to Windows Forms.

Interface
In previous releases, the common class interface was always hidden for users. In Visual
Basic.NET, common classes can be browsed and edited in the Code window.

Upgrade reports and comments
When the project is upgraded, the upgrade report is added to your project, detailing all liters
After the level you need to make changes to the code. The code also adds a comment that prompts you to notice any potential problems. These annotations appear automatically in the
In the task List of Visual Basic.NET.


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.