by Bhuwan Chand Joshi (69 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 10th June 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
What is VB.Net? Technical article with small code samples and language changes from VB 6.0. to VB.Net
VisualBasic.Net is the next higher version of Micrsoft Visual Basic with more enhancements of object oriented concepts in a language to make it easier to write distributed applications and enterprise n-tier applications in a very less time.
VisualBasic.Net uses the CLR (Common Language Runtime), the common runtime used by all other Microsoft Visual Studio.Net Languages. So VB-Specific runtime is no more.
VisualBasic.Net truly supports Object Oriented features like inheritance, free-threaded Multithreading model, overloading etc.
VisualBasic.Net is fully integrated with other Microsoft Visual Studio.Net languages. User defined classes in VisualBasic.Net can inherit from classes written in other Microsoft Visual Studio.Net languages using CLR (Common Language Runtime).
VisualBasic.Net has two forms packages : Windows Forms and Web Forms. Using Web Forms and ADO.Net, application programmers are able to create scalable web sites.
VisualBasic.Net objects can be shared among other Microsoft Visual Studio.Net languages because of CLR (Common Language Runtime).
Microsoft has a Migration Wizard that converts VB 6.0 code to VisualBasic.Net when you load a VB 6.0 project into Microsoft Visual Studio.Net environment.
VB.Net has come up with advanced features of object oriented, which make language more streamlined and provides advanced low-level construct that developers require. There are number of changes have been made to the language. We are discussing the following changes with you:
Data Types
Arrays
Looping Constructs
Debug.Print
Calling Procedures
Currency Data Type
Variant
Empty
VB Constants
File I/O
Concatenation Operator
Fixed-Length Strings
Declaring Variables and Arrays
String Operators
Explicit Casting
Concept1:
Every langauge has its own data types to store the values. Data types supported by VB.Net language are:
Byte - 1 Byte
Char - 2 Bytes
Boolean - 4 Bytes
Decimal - 12 Bytes
Double - 8 Bytes
Short - 2 Bytes
Integer - 4 Bytes
Long - 8 Bytes
Single - 4 Bytes
In Visual Basic 6.0 Long data type stores 32-bit numbers and Integer stores 16-bit numbers but in VisualBasic.Net Long stores 64-bit numbers, integer stores 32-bit numbers and short stores 16-bit numbers.
Visual Basic 6.0 data type declaration as in the following example
Dim A as Integer
Dim B as Long
The above example is upgraded in VB.Net as :
Dim A as Short
Dim B as Integer
Concept 2:
Like data types, arrays are used to store multiple values at a time. In VB.Net, each array has a lower bound of 0. So Option Base statement of Visual Basic 6.0 is no more.
Array declaration in Visual Basic 6.0 as in the following example
Dim arrEmployee(1 to 51) as String
The above example is upgraded in VB.Net as
Dim arrEmployee(50) as String
Concept 3:
Looping Constructs If..Then, Do..Loop, For...Next, While..Wend are the most important part of VB language to test the various kind of expressions. All the construct remains same in VB.Net as in VB 6.0 except While..Wend. While..Wend Loop construct has now been changed into While..End While in VB.Net.
Using While..Wend statement of Visual Basic 6.0 as in the following example
Dim intCounter as Integer
intCounter=0
While intCounter <> 5
intCounter = intCounter + 1
Wend
The above example is upgraded in VB.Net as :
Dim intCounter as Short
intCounter=0
While intCounter <> 5
intCounter = intCounter + 1
End While
Concept 4:
Debug.Print outputs a line of text in a immediate window. Debug.print now converted into Debug.WriteLine in VB.Net.
Using Debug.Print statement of Visual Basic 6.0 as in the following example
Dim intCounter as Integer
intCounter=0
While intCounter <> 5
intCounter = intCounter + 1
Debug.Print intCounter
Wend
The above example is upgraded in VB.Net as :
Dim intCounter as Short
intCounter=0
While intCounter <> 5
intCounter = intCounter + 1
Debug.WriteLine(intCounter)
End While
Concept 5:
You can call procedures in Visual Basic 6.0 in two forms. You can call procedures either with Call statement which requires parentheses around the argument list or without Call statement which do not requires parentheses. In VB.Net parentheses are must around the argument list while calling procedures.
Call statement of Visual Basic 6.0 as in the following example
Public Sub AcceptName(ByVal strMyName as String)
MsgBox strMyName, vbOkOnly
End Sub
Public Sub MyName()
AcceptName "Bhuwan Joshi"
End Sub
The above example is upgraded in VB.Net as :
Public Sub AcceptName(ByVal strMyName as String)
MsgBox strMyName, vbOkOnly
End Sub
Public Sub MyName()
AcceptName("Bhuwan Joshi")
End Sub
Concept 6:
Currency data type of Visual Basic 6.0 does not prove to avoid rounding errors with accuracy, so Currency data type is replaced with Decimal data type in VB.Net.
Currency data type of Visual Basic 6.0 as in the following example
Dim A as Currency
The above example is upgraded in VB.Net as :
Dim A as Decimal
Concept 7:
Variant is a default data type in Visual Basic 6.0. Variant is a special data type that can store any kind of data except fixed-length string. Common Language Runtime of .Net environment uses Object data type to store any kind of data, so Variant is no more in VB.Net.
Variant data type of Visual Basic 6.0 as in the following example
Dim A as Variant
The above example is upgraded in VB.Net as :
Dim A as Object
Concept 8:
The Empty keyword is used as Variant subtype in Visual Basic 6.0. It indicates an uninitialized value of a variable. A variant variable has a Empty value before it is assigned a value. This Empty keyword is replaced with Nothing in VB.Net to increase language interoperability.
Empty keyword of Visual Basic 6.0 as in the following example
If IsEmpty(intCounter) Then intCounter=0
The above example is upgraded in VB.Net as :
If IsNothing(intCounter) Then intCounter=0
Concept 9:
Use of constants name in VB.Net instead of underlying values is highly recommended.
Constants of Visual Basic 6.0 as in the following example
Form1.WindowState=2
The above example is upgraded in VB.Net as :
Form1.WindowState=vbMaximized
Concept 10:
In Visual Basic 6.0 File I/O statements are included in the language while in VB.Net File I/O operations are available only through class libraries. Removing the file I/O statements from the language allows different I/O libraries to be easily used from Visual Basic .NET.
File I/O Concept of Visual Basic 6.0 as in the following example
Open "Test.txt" For Input As #1
The above example is upgraded in VB.Net as :
FileOpen( 1, "Test.txt",OpenMode.Input )
Concept 11:
VB.NET has a new set of concatenation operators. C++ programmers are very much familiar with these operators.
A &= B -----> A = A & B
A *= B -----> A = A & B
A += B -----> A = A & B
A /= B -----> A = A & B
A -= B -----> A = A & B
A \= B -----> A = A & B
A ^= B -----> A = A & B
Example of using concatenation operators in VB.Net
Sub ConcatenateName()
Dim strName as String
strName = "Bhuwan"
strName += " Joshi"
Debug.WriteLine(strName)
End Sub
Concept 12:
Why do you need a Char data type in VB.Net? Because Fixed-Length strings are no more in VB.Net.
Fixed-Linked Strings of Visual Basic 6.0 as in the following example
Dim myName as String * 6
The above example is upgraded in VB.Net as :
Dim myName As New VB6.FixedLengthString(6)
You can also use Char data type to define fixed strings.
Concept 13:
VB.Net allows you to declare multiple variables on a single line. It also allows to intialize both variables and arrays at declaration line.
Example of declaring variables and arrays
Sub MyName()
Dim FirstName, LastName as String
Dim strMyName as String = "Bhuwan Joshi"
Dim strFirstName() as String = {"B", "H", "U", "W", "A", "N"}
Dim strLastName() as String ={"J", "O", "S", "H", "I"}
End Sub
Concept 14:
In Visual Basic 6.0, there is no conversions that lead to an unexpected results, for example, 10 + "10" could result in 20. Therefore, for strict type of checking, VB.Net has separated concatenation operators for strings.
String Operators Example
Sub MyName()
Dim strMyName as String = "BHUWAN"
Debug.WriteLine(instr(strMyName, "U"))
Debug.WriteLine(strMyName.IndexOf("U"))
End Sub
Concept 15:
A new feature of Explicit Casting has been introduced into a language. VB 6.0 perform intelligent type casting for you, for example, Long to Integer, sometimes perform wrong result and unable to give you runtime errors but in VB.Net explicit cast is must.
Explicit Cast Example
Sub Test()
Dim intX as integer, lngY as Long
intX = 100
lngY = intX
Debug.WriteLine(lngY)
lngY = 200
intX = CInt(lngY) ' Explicit Cast Needed Here
Debug.WriteLine(intX)
End Sub
I will definitely write more on VB.Net. Visit my site http://www.vbcodemaster.com for Graphics Technologies and visit my another site http://www.vbexpertoffice.com to submit your VB.Net codes. Contact me at [email protected].
Thanks
Bhuwan Chand Joshi
Webmaster / VBProgrammer
VBCodeMaster.com / VBExpertOffice.com
No comments have been posted about What is VB.Net? Technical article with small code samples and language changes from VB 6.0. to VB.N. Why not be the first to post a comment about What is VB.Net? Technical article with small code samples and language changes from VB 6.0. to VB.N.