Search Interview Questions
Question: What is the difference between VB and VB.NET?
Answer: 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.
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.
Dim readonly x as integer
In later code
Now x can’t be changed
X=200 *********** Error **********
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
M_var = value
Private _message as String
Public Property Message As String
_message = Value
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
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
If objRs("flag")="Y" then
If J Then
Msgbox "Flag is Y"
In the above example the variable J will become out of scope just after the loop, since J was declared inside the While loop.
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.
Open "myFile" For Output As #1
Write #1, myOutput
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
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:
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
To create a static method in a VB.NET, simply prefix the method definition with the keyword Shared.
Question: What is the difference between VB and VB.NET?
What is the difference between VB and VB.NET?
If you have the better answer, then send it to us. We will display your answer after the approval
Rules to Post Answers in CoolInterview.com:-
|What is the difference between ADO and ADO.NET?||
|What is Web.config?||
|What is Machine.config?||
|Using COM Component in .Net||
|Using ActiveX Control in .Net||
|Differences between Datagrid, Datalist and Repeater?||
|Advantages of VB.NET||
|Advantages of migrating to VB.NET||
|Observations between VB.NET and VC#.NET||
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
India News Network
Latest 20 Questions
Payment of time- barred debt is:
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal