Comparison of Visual Basic 6/vbscript with Visual Basic.NET (top)

Source: Internet
Author: User
Tags arrays comparison exception handling integer variables variable scope versions
Vbscript|visual because the environment of the future Microsoft. NET platform differs greatly from today, the future class can be inherited in language, that is, VB can inherit C # class and so on. The original code is translated into Managed code, and the platform provides the time to translate IL into a password and so on. VB must be in order to get rid of the fetal bone. So the Visual Basic.NET will have an absolutely big facelift, very different from the previous six versions.

Visual Basic.NET and previous versions are actually so much worse that there's no way to do this in one by one. Only the obvious and reusable parts. < visual Basic 6 and Visual Basic.NET the difference between the sections > The following is a introduction to the parts of Vb6/visual Basic.NET, but Visual Basic.NET changes usage or keyword updates. Content has
    • Set and let are no longer used
    • The attributes of Class
    • Subroutines and functions
    • Complete Information Model
    • Declaring variables, constants, and arrays
    • Variable range (Variable Scope)
    • Structured exception processing (structured Exception handling)
    • Using the correct data type
    • User-customized data structure (Structure)
Set and let are no longer used with set and let, unless the class file is set to a character. Because the default attributes and methods are no longer used in Visual Basic.NET, you do not need to rely on them to identify the variable value when you use the method and the attributes of the object. That is, originally in VB6, to set the variable obj inside objthis, you must
Set Obj=objthis
and receiving the preset can
Att=objthis and Att=objthis.defaultatt two ways to write
So if a Objthis object has a preset called Defaultatt, it's not clear whether the Set will be accessing Objthis objects or Objthis.defaultatt this preset. But when it comes to Visual Basic.NET, if you're going to read Defaultatt because there's no way to use it, you only (and must) read the Defaultatt in Objthis.defaultatt.
So when you use the following code
Obj=objthis
It must be objthis this object, not simulate two. This notation is more akin to the language of Visual Basic.NET and JavaScript and C #.
The attributes of Class in Visual Basic.NET
In VB 6 to write the attributes of an object will use the following code, where property gets is used to allow the user to read the attributes, and the property Set/let is used to set the attributes, so whether to use set or let is to see whether the given property is an object or a general variable type.
Private M_myproperty as Variant


Public Property Get MyProperty () as Variant
If IsObject (M_myproperty)
Then Set MyProperty = M_myproperty
Else
MyProperty = M_myproperty
End If
End Property


Public Property Set MyProperty (ByVal vnewvalue as Variant)
Set M_myproperty = Vnewvalue
End Property


Public Property Let MyProperty (ByVal Vnewvalue as Variant)
M_myproperty = Vnewvalue
End Property
But the code in Visual Basic.NET is changed to
Private M_myproperty as String
Public Property MyProperty () as String
Get
MyProperty = M_myproperty
End Get


Set
M_myproperty = Value
End Set
End Property

This language is also similar to the C # language.

In addition, in Visual Basic.NET you have to be sure to use the ReadOnly or WriteOnly key to determine whether the attributes are read-only or write-only, so the code
Public ReadOnly Property MyProperty () as String
Get
MyProperty = M_myproperty
End Get
End Property
Or

Public WriteOnly Property MyProperty () as String
Set
M_myproperty = Value
End Se
T End Property

Subroutines and Functionsvisual Basic.NET also have many changes in call and use subroutine and Function.

Method of calling change--all methods, subroutine, and function calls need to be preceded by a small parentheses, in the past call function but do not need a function of the return value, or function does not need to pass the parameters, you can use the way without the small parentheses, Or call subroutine do not use the small parentheses and so on is OK, but in the Visual Basic.NET are not allowed. So in VB 6 of the
Dattime=now ' Call system's now () function
Or
DoSomething "Par1", Int2, "Par3" ' Call-back function dosomething, three of parameters, etc. to be changed to Dattime=now ()
Or
DoSomething ("Par1", Int2, "Par3")
So be careful in asp+
Response.Write "some text"
and change it to
Response.Write ("some text")
The parameters are programmed to ByVal--if the VB6 parameters are not set, a preset is a way to give a secondary function as a ByRef, but the Visual Basic.NET is changed to a preset to ByVal the value of the variable to the secondary function.
But it is to be noted that the Classes and interfaces as well as array and string are still used ByRef

Use the return method--visual Basic.NET does not support VB6 for the GoSub language used for forward compatibility (where J exists from Basic). The return language is now dedicated to returning control to the caller side within a Function or Sub.

Complete Information Model
In VBScript, only Variant data types are supported, whereas in Visual Basic.NET all things are objects (object) that contain intrinsic data types. And Variant is just a special type of object.

Variant types are generally less efficient to use, but may be easier to use in some places, such as from the repository to take a possible return of NULL, code such as the right Dim rec as Recordset
Set rec = New Recordset
Rec. Open "Select Region from Northwind.dbo.Customers WHERE customerid= ' ALFKI '", "Provider=sqloledb;data souce= (local); Nitail Catalog=northiwnd; User Id=sa; "
Dim Res as Variant
res = rec. Fields (0)
If IsNull (RES) Then
MsgBox "Content is Null"
Else
MsgBox Res
End If intrinsic data type in Visual Basic.NET type name size preset value Byte1 byte (8 bits) 0 Short2 bytes (bits) 0 Integer4 bytes (32 Bits) 0 Long8 bytes (+ bits) 0 Single4 bytes (0.0Unicode bits) 0.0 Double8 (bits) bytes 0.0 Decimal12 Literal string "Char 2 bytes (bits)" Other Boolean False Date #01/01/0001 12:00:00am# Note that no longer supports Currency type, you can use the Decimal type instead

Declaring variables, constants, and arrays
In Visual Basic.NET there are some additions to the declaration of variables, constants, and arrays, which, at the same time, can be given value-the declaration of the Language and the act of the language similar Dim x as integer=24
Dim y as integer= x*24


Const my_number=42
Const My_number as Integer=42
Const my_string = "Hello World"
The Const my_string as String = "Hello World" note that incompatible with VB6 is a form that can only be pronounced in the same declarative language, so the following languages cannot be used.
Dim x as Integer, y as String
Also therefore
Dim X,y as Integer
Will declare that both the X and Y variables are integral types. The Dim key can also declare an initialized array
Dim MyArray as Integer
Dim MyArray (5) as Integer = (1,2,3,4,5)
Dim MyArray (3) as String = ("Bill", "Fred", "Mary")
The array must be declared through Dim, and in an empty parenthesis, the array can then be redefined to size. ReDim can be used to redefine the size of the array, but not to change the dimensions of the array.
Dim myarray () as Integer
ReDim MyArray (20)


Dim MyArray (,,) ' <---Define the dimensions of the array through the tease
ReDim MyArray (20,10,5)

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.