GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Microsoft  >  DotNet
Go To First  |  Previous Question  |  Next Question 
 DotNet  |  Question 85 of 165    Print  
What is the difference between VB and VB.NET?
Now VB.NET is object-oriented language. The following are some of the differences:
Data Type Changes
The .NET platform provides Common Type System to all the supported languages. This means that all the languages must support the same data types as enforced by common language runtime. This eliminates data type incompatibilities between various languages. For example on the 32-bit Windows platform, the integer data type takes 4 bytes in languages like C++ whereas in VB it takes 2 bytes. Following are the main changes related to data types in VB.NET:
• Under .NET the integer data type in VB.NET is also 4 bytes in size.
• VB.NET has no currency data type. Instead it provides decimal as a replacement.
• VB.NET introduces a new data type called Char. The char data type takes 2 bytes and can store Unicode characters.
• VB.NET do not have Variant data type. To achieve a result similar to variant type you can use Object data type. (Since every thing in .NET – including primitive data types – is an object, a variable of object type can point to any data type).
• In VB.NET there is no concept of fixed length strings.
• In VB6 we used the Type keyword to declare our user-defined structures. VB.NET introduces the structure keyword for the same purpose.
Declaring Variables
Consider this simple example in VB6:
Dim x,y as integer
In this example VB6 will consider x as variant and y as integer, which is somewhat odd behavior. VB.NET corrects this problem, creating both x and y as integers. Furthermore, VB.NET allows you to assign initial values to the variables in the declaration statement itself:
Dim str1 as string = “Hello”
VB.NET also introduces Read-Only variables. Unlike constants Read-Only variables can be declared without initialization but once you assign a value to it, it cannot be changes.
Initialization here
Dim readonly x as integer
In later code
X=100
Now x can’t be changed
X=200 *********** Error **********
Property Syntax
In VB.NET, we anymore don't have separate declarations for Get and Set/Let. Now, everything is done in a single property declaration. This can be better explained by the following example.
Public [ReadOnly | WriteOnly] Property PropertyName as Datatype
Get
Return m_var
End Get

Set
M_var = value
End Set
End Property
Example:
Private _message as String
Public Property Message As String
Get
Return _message
End Get
Set
_message = Value
End Set
End Property
ByVal is the default - This is a crucial difference betwen VB 6.0 and VB.NET, where the default in VB 6.0 was by reference. But objects are still passed by reference.
Invoking Subroutines
In previous versions of VB, only functions required the use of parentheses around the parameter list. But in VB.NET all function or subroutine calls require parentheses around the parameter list. This also applies, even though the parameter list is empty.
User-Defined Types - VB.NET does away with the keyword Type and replaces it with the keyword Structure
Public Structure Student
Dim strName as String
Dim strAge as Short
End Structure
Procedures and Functions
In VB6 all the procedure parameters are passed by reference (ByRef) by default. In VB.NET they are passed by value (ByVal) by default. Parantheses are required for calling procedures and functions whether they accept any parameters or not.
In VB6 functions returned values using syntax like: FuntionName = return_value. In VB.NET you can use the Return keyword (Return return_value) to return values or you can continue to use the older syntax, which is still valid.
Scoping
VB.NET now supports block-level scoping of variables. If your programs declare all of the variables at the beginning of the function or subroutine, this will not be a problem. However, the following VB 6.0 will cause an issue while upgrading to VB .NET

Do While objRs.Eof
Dim J as Integer
J=0
If objRs("flag")="Y" then
J=1
End If
objRs.MoveNext
Wend
If J Then
Msgbox "Flag is Y"
End If
In the above example the variable J will become out of scope just after the loop, since J was declared inside the While loop.
Exception Handling
The most wanted feature in earlier versions of VB was its error handling mechanism. The older versions relied on error handlers such as "On Error GoTo and On Error Resume Next. VB.NET provides us with a more stuructured approach. The new block structure allows us to track the exact error at the right time. The new error handling mechanism is refered to as Try...Throw...Catch...Finally. The following example will explain this new feature.
Sub myOpenFile()
Try
Open "myFile" For Output As #1
Write #1, myOutput
Catch
Kill "myFile"
Finally
Close #1
End try
End Sub
The keyword SET is gone - Since everything in VB.NET is an object. So the keyword SET is not at all used to differentiate between a simple variable assignment and an object assignment. So, if you have the following statement in VB 6.0
Set ObjConn = Nothing
Should be replaced as
ObjConn = Nothing.
Constructor and Destructor
The constructor procedure is one of the many new object-oriented features of VB.NET. The constructor in VB.NET replaces the Class_Initialize in VB 6.0. All occurance of Class_Initialize in previous versions of VB should now be placed in a class constructor. In VB.NET, a constructor is added to a class by adding a procedure called New. We can also create a class destructor, which is equivalent to Class_Terminate event in VB 6.0, by adding a sub-procedure called Finalize to our class.
Usage of Return
In VB.NET, we can use the keyword return to return a value from any function. In previous versions, we used to assign the value back with the help of the function name itself. The following example explains this:
Public Function Sum (intNum1 as Integer, intNum2 as Integer) as Integer
Dim intSum as Integer
intSum = intNum1 + intNum2
Return intSum
End Function
Static Methods
VB.NET now allows you to create static methods in your classes. Static methods are methods that can be called without requiring the developer to create instance of the class. For example, if you had a class named Foo with the non-static method NonStatic() and the static method Static(), you could call the Static() method like so:
Foo.Static()
However, non-static methods require than an instance of the class be created, like so:
Create an instance of the Foo class
Dim objFoo as New Foo()
Execute the NonStatic() method
ObjFoo.NonStatic()
To create a static method in a VB.NET, simply prefix the method definition with the keyword Shared.



  
Total Answers and Comments: 2 Last Update: December 21, 2008   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
January 16, 2006 07:35:22   #1  
samiksc Member Since: October 2005   Contribution: 233    

RE: What is the difference between VB and VB.NET?

To summarize points of difference are as follows:

  1. VB.Net is object oriented while VB is procedural
  2. VB.Net enjoys benefits of .net memory management and CTS
  3. VB.Net supports advanced features like exception handling.
  4. VB.Net uses ADO.Net which supports XML representation of objects. These objects are lightweight and travel through firewalls. VB uses ADO recordsets which are binary COM objects.

 
Is this answer useful? Yes | No
December 20, 2008 14:43:25   #2  
John B Member Since: December 2008   Contribution: 1    

RE: What is the difference between VB and VB.NET?
The big one is that VB (we are talking VB through VB6) is entirely in the COM world not the .Net world of managed code. VB generates either threaded P-code or native EXE processed by the VB runtime but does not have concept of Release vs Debug. VB.Net generates IL that is processed on a just-in-time-compile basis by the CLR and offers Release and Debug options.
VB had "some" object-oriented features- interfaces classes instantiation - but lacked inheritance and other things VB.Net is full OO. VB had deterministic object release: set an object to Nothing and it was gone: .Net releases the memory during system-determined passes of the general Garbage Collector.
There are lots of other differences many listed in the very long answer to the question! Many people feel that much of the ease and speed of use of VB was sacrificed in making VB.Net more of a "geeky" language and that some of these aspects could have been retained - for instance surely there was a way to generate IL for control arrays?

 
Is this answer useful? Yes | No

 Related Questions

What is the difference between Servers? Transfer and Response. Redirect? Why would I choose one over the other?

Latest Answer : In ADO, the in-memory representation of data is the recordset. In ADO.NET, it is the dataset. There are important differences between them. A recordset looks like a single table. If a recordset is to contain data from multiple database tables, ...

Describe the difference between inline and code behind - which is best in a loosely coupled solution.

Latest Answer : Dataset:-Data set is the Disconneted data Architecture.Datareader:- Datareader is the connected Data Architecture. ...

A namespace is a logical naming scheme for types in which a simple type name, such as MyType, is preceded with a dot-separated hierarchical name. Such a naming scheme is completely under control of 
Latest Answer : Namespace - It is a logical group of classes means it defines boundary for classes. In a single program 2 namespace cannot be have same name. Assemblies - These physical structure of coding and it can store manifest (metadata). Assembly can be ...

What is the difference between "using System.Data;" and directly adding the reference from "Add References Dialog Box"?
When u compile a program using command line, u add the references using /r switch. When you compile a program using Visual Studio, it adds those references to our assembly, which are added using "Add 

ASP ASP.NET ASP is interpreted. ASP.NET Compiled event base programming. Control events for text button can be handled at client javascript only. Since we have server controls 
Latest Answer : To summarize the points of differences are as follows:Code behind in asp.net allows separation of business logic from UI, which is not possible in asp.ASP.Net uses ADO.Net objects which are represented using XML, and hence they are lightweight and can ...

Now VB.NET is object-oriented language. The following are some of the differences:Data Type Changes The .NET platform provides Common Type System to all the supported languages. This means that all 
Latest Answer : The big one is that VB (we are talking VB through VB6) is entirely in the COM world not the .Net world of managed code. VB generates either threaded P-code or native EXE, processed by the VB runtime,  but does not have concept of Release vs Debug. ...

ADO uses Recordsets and cursors to access and modify data. Because of its inherent design, Recordset can impact performance on the server side by tying up valuable resources. In addition, COM marshalling 
Latest Answer : Even in ADO there is a concept of shaped queries where we can access the records from multiple tables without using joins. ...

Latest Answer : Syntactically, Visual Basic .NET and Visual C# .NET are two different languages, just as Visual Basic, Visual C, and Visual C++ are different languages. Visual C# .NET looks more familiar to Visual C, Visual C++, and Java programmers, and Visual Basic ...
Read Answers (2) | Asked by : Gopal


 Sponsored Links

 
Related Articles

What is difference between call by value and call by reference in function?

The arguments passed to function can be of two types 1. Values passed 2. Address passed The first type refers to call by value and the second type refers to call by reference. For instance consider program1 main() { int x=50, y=70; interchange(x,y); printf(“x=%d y=%d”,x,
 

The Interview Snafu

How to turn someone else’s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won’t get over the line without a polished, prof
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

Difference between Scholarship and Grant

Difference between Scholarship and Grant While both scholarships and grants allow students to pay for their tuition without having to pay the money back there are a number of key differences between the two Knowing the difference between grants and scholarship will make it much easier for students t
 

HR Interview - HR Interview Mistakes You Will Want To Avoid

HR Interview Mistakes You Will Want To Avoid The job interview can be a stressful process This is especially true for those who are going after a competitive position Your nonverbal communication combined with the answers you give during the interview will determine if you are hired mosgoogle While
 

HR Interview - Behavioral HR Interviews

Behavioral HR Interviews As the name implies a behavioral interview is an interview that is held by a human resources department to determine if an applicant has the behaviors that are appropriate for a job The company must know how an applicant will behave in a certain situations mosgoogle The logi
 

HR Interview - How To Prepare For Your HR Interview

How To Prepare For Your HR Interview Before you begin thinking about how you are going to dress for the interview it is important to do your research first You should learn everything you can about the company you wish to work for When you have detailed information about your employer you will conve
 

HR Interview - Telephone Interview Etiquette

Telephone Interview Etiquette When you conduct a telephone interview for a job it is important to show the proper etiquette Not only is it important it is critical is you wish to be hired by the company There are a number of things you will want to do and other things should never be done mosgoogle
 

HR Interview - How To Succeed At HR Interviews

How To Succeed At HR Interviews There are a number of things you will need to do in order to make sure you pass the interview process Your appearance is something that you will want to pay close attention to Even if you feel that your appearance shouldn t be a factor in whether or not you re highere
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape