Skip to main content

Difference between VB 6 and VB.NET

Data Type Changes

The .NET Framework has classes that define the Common Type System that allow for data types to be consistent across applications written in different .NET languages. Because of this, Visual Basic needed to change the types of data it supports and numeric ranges of existing data types.

Variant not supported

In VB6, the Variant data type was the default universal data type; this was replaced by the Object data type in VB.NET. The default value for Object data type is Nothing, whereas the default value for Variant data types was Empty.

Dim variable1 as Variant

Changes to:

Dim variable2 as Object

Integer and Long

In VB6, the Integer data type was a 16-bit number, ranging in value from -32,767 to 32,767. The Short data type replaces Integer as a 32-bit number in VB.NET, and the Integer data type now ranges from -2,147,483,648 to 2,147,483,647. The Long data type is now a 64-bit number. Using Integer for 32-bit operations is the most efficient data type.

            Dim x as Integer
            Dim y as Long

Changes to:

            Dim x as Short
            Dim y as Integer

Currency not supported

The Currency data type is changed to decimal in VB.NET. Decimal is more accurate for rounding numbers, so the Decimal data type was created to handle currency operations. Currency was a 64-bit number, with 4 digits to the right of the decimal place. The new Decimal data type is a 96-bit signed integer and can have up to 28 digits to the right of the decimal place.


            Dim x as Currency

Changes to:

            Dim x as Decimal

Strings

Fixed-length strings are no longer supported.

DefType not supported

The DefType statement, which gives a default type for all variables declared without a type, is no longer supported. DefInt, DefStr, DefBool, and DefLng are no longer supported.

Arrays

One of the biggest issues when Microsoft announced the language changes in VB.NET was the lower-dimension arrays. From the beginning, Visual Basic has always allowed the lower bound of an array to be either 0 or 1. The Option Base statement, which is no longer supported, dictated whether all arrays should be treated as 0-based or 1-based. In the end, Microsoft decided that all arrays will have a default lower bound of 0, meaning that existing code using Option Base 1 statement will need to be revisited to ensure that there is no data loss or corruption, because the size of the array will be different.

Arrays cannot be fixed

Arrays cannot be declared as fixed sizes by specifying the lower and upper bounds at design time. You now declare just the upper bound to the array, with zero being the default lower bound.

            Dim x (0 to 5) as string           ‘ 6 item array

Changes to:

            Dim x (5) as string                  ‘ 6 item array

Or

            Dim x as string = new string(5) ‘ 6 item array

ReDim changed

The ReDim statement cannot be used in the declaration of any array variable. in VB.NET, you declare an array using Dim, and then use the ReDim statement to alter the bounds of the array.

The Value of True

In VB6, the value of true is -1. This is the same in VB.NET, however, in the CLR; the value of the true is equal to 1. When passing Boolean variables between languages in the .NET Framework, -1 will be true, and 1 in all other languages.

Operators

Some of the most exciting language changes in VB.NET have come in the category of operators. Table lists the new assignment operators, which will mean less typing for you when you are using operators.

EQV

The EQV operator is replaced with the “=” assignment operator.

Short-circuiting

The AndAlso and OrElse operators have been defined to handle short-circuiting. All other operators will remain the same. In short, circuiting means if the first part of an expression returns false, then remainder of the expression is ignored and false is returned.

Dim x as Integer = 5
Dim y as Integer = 6
Dim z as Integer = 7
ret = x > y AndAlso z > y          ‘ Return false, 5 is not greater than 6

Assignment

VB.NET offers some cool new assignment operators.

            Dim x as Integer
            x = x + 1

Can now be changed to:

            Dim x as Integer
            x+=1


Operator
Action
+=
Addition and concatenation
-=
Subtraction
*=
Multiplication
/= and \=
Division
^=
Exponentiation
&=
String concatenation


Null Values

Null propagation is not supported. Value types that are null are passed to functions as the DBNull data types. To test for null values, the IsNull statement is no longer supported. It is replaced with the DBNull statement.

            If IsNull (field) then . . .

Changes to:

            If IsDBNull (field) then . . .

The IsEmpty statement is not supported. In VB6, the values NULL and Empty could be used to check for a variable that has not been initialized or for a variable that contains no data. Null and Empty are no longer a valid means to check for this information, making IsEmpty obsolete. The nothing keyword should now be used to check for these conditions.

Variable Initialization

Variables can now be initialized to a value on the same line in which they are declared.

            Dim x as integer
            x = 5

Can be changed to:

            Dim x as Integer = 5

Also, now you can declare multiple variables on the same line, with a single type

            Dim str1, str2, str3 as String

Language Issues

One of the biggest defy when upgrading to VB.NET will be learning the replacements for existing functions.

IsMissing

The IsMissing function is no longer supported and is replaced with the IsNothing statement.

Date$ and Time$

The Date$ and Time$ functions in VB6 to return a string representation of the current date or time are replaced by the DateString and TimeString methods in VB.NET.

Procedures

Because VB.NET fully supports object-oriented features, there have been critical changes in procedure scope, returning values, and the type of procedures you can use.

Calling procedures

Calling procedures, either subs or functions, now require parentheses for the argument list, even if there are no arguments.

            Sub test()
                        ‘code
            End Sub
            Call test

Changes to:

            Call test()

Static procedures

Static procedures are no longer supported. If you use static procedures , you should change them to regular subprocedures and define the variables within the static.

            Static Sub Test()
                        Dim x as Integer
            End Sub

Changes to

            Sub Test()
                        Static x as Integer
            End Sub

ByVal and ByRef

The default behavior of ByVal and ByRef has changed. In VB6, the default for passing parameters was ByRef. In VB.NET, ByVal is the default mechanism for passing variables to procedures.

While . . . Wend

The While … Wend construct is no longer supported. It is replaced with While … End While.

            While x < 5
                        ‘code
            Wend

Changes to

            While x < 5
                        ‘code
            End While

Caption property

The Caption property of label controls and forms is no longer supported. The Text property replaces the Caption property.

            Label1.Caption = “VB.NET for developing applications”
            Form1.Caption = “New Form”

Changes to:

            Label1.Text = “VB.NET for developing applications”
            Form1.Caption = “New Form”

Image Control

The image control is replaced with the PictureBox control in VB.NET.

Webclasses

Webclass applications are no longer supported. Web Forms applications should be used to write Web-based applications. The power and functionality provided in using Web Services and ASP.NET applications will give much more flexibility than programming Webclasses applications ever did.



 Resource Used: VB.NET (Bible)

Compiled By: Chaudhary Amit V.

Comments

  1. Really I understood about the new version of vb6..
    I understand the diff.
    thnks dear

    ReplyDelete

Post a Comment

Popular posts from this blog

Characteristics of a Good Programming Language

Till now there are many high level languages which are very popular, and there are others, which could not become so popular in-spite of being very powerful. There might be many reasons for the success of a language, but one obvious reason is the characteristics of the language. Several characteristics believed to be important with respect to making a programming language good are briefly discussed below. Simplicity A good programming language must be simple and easy to learn and use. For example, BASIC is liked by many programmers only because of its simplicity. Thus, a good programming language should provide a programmer with a clear, simple and unified set of concepts which can be easily grasped. It is also easy to develop and implement a compiler or an interpreter for a programming language that is simple. However, the power needed for the language should not be sacrificed for simplicity. The overall simplicity of a programming language strongly affects the readability of the pr...

Angular 4 and Firebase Authentication: Email/Password

In our  previous  article we saw how to create authentication module using Google identity provider. Now we will see how to implement Email and Password authentication using Firebase. We will use Bootstrap form to create intuitive user interface for sign-up and login using Email and Password. Step 1: Create signUp component. ng generate component signUp Step 2: Create custom form in sign-up.component.html file. The result of above code: Step 3: Add two functions for creating the user and login using Email and Password in src/app/providers/AFAuth.ts file. Step 4: Call createUserWithEmailAndPassword function in service from sign-up.component.ts. Step 5: Update routing configuration in app.module.ts  to include signUp component. Step 6: Update Login form to have Bootstrap form. The result of the above code. Step 7: Enable Email/Password component in Firebas...

Angular 4 and Firebase Authentication: Setup

If you have come to this article, it means you are keen to learn new technology and that too Firebase. I love Firebase because it provides all basic but important features of any web application. Take for example, authentication, which is cumbersome and risky if not implemented with utmost care. And when we have the integration of Angular and Firebase, it becomes a lot easier for a developer to build such crucial modules in less time with minimal efforts. In this article we will create a simple Angular application using Firebase. I am going ahead with the understanding that you know the benefits of Firebase and have little knowledge about it. There are plenty of posts out on the web if you are behind. Step 1: Install Angular CLI (if not installed). npm install -g angular-cli Step 2: Create new Angular 4 project. By default now angular CLI will create Angular 4 project so you need not fret. ng new firebase-authentication Step 3: Check whether the ne...