INTRODUCTION_TO_VB
INTRODUCTION_TO_VB
NET
1. VB.NET– Overview
Like all other .NET languages, VB.NET has complete support for object-oriented concepts.
Everything in VB.NET is an object, including all of the primitive types (Short, Integer, Long,
String, Boolean, etc.) and user-defined types, events, and even assemblies. All objects
inherits from the base class Object.
VB.NET is implemented by Microsoft's .NET framework. Therefore, it has full access to all the
libraries in the .Net Framework. It's also possible to run VB.NET programs on Mono, the
opensource alternative to .NET, not only under Windows, but even Linux or Mac OSX.
• Object oriented.
• Component oriented.
• Easy to learn.
• Structured language.
VB.Net has numerous strong programming features that make it endearing to multitude of
programmers worldwide. Let us mention some of these features:
• Boolean Conditions
1
• Automatic Garbage Collection
• Standard Library
• Assembly Versioning
• Properties and Events
• Easy-to-use Generics
• Indexers
• Conditional Compilation
• Simple Multithreading
VB.NET
2. VB.NET– EnvironmentSetup
In this chapter, we will discuss the tools available for creating VB.Net applications.
We have already mentioned that VB.Net is part of .Net framework and used for writing .Net
applications. Therefore before discussing the available tools for running a VB.Net program,
let us understand how VB.Net relates to the .Net framework.
The .Net framework is a revolutionary platform that helps you to write the following types of
applications:
• Windows applications
• Web applications
• Web services
2
The .Net framework applications are multi-platform applications. The framework has been
designed in such a way that it can be used from any of the following languages: Visual Basic,
C#, C++, Jscript, and COBOL, etc.
All these languages can access the framework as well as communicate with each other.
The .Net framework consists of an enormous library of codes used by the client languages
like VB.Net. These languages use object-oriented methodology.
• Windows Forms
• ADO.Net
• LINQ
For the jobs each of these components perform, please see ASP.Net - Introduction, and for
details of each component, please consult Microsoft's documentation.
3
• Visual Web Developer
The last two are free. Using these tools, you can write all kinds of VB.Net programs from
simple command-line applications to more complex applications. Visual Basic Express and
Visual Web Developer Express edition are trimmed down versions of Visual Studio and has
the same look and feel. They retain most features of Visual Studio. In this tutorial, we have
used Visual Basic 2010 Express and Visual Web Developer (for the web programming
chapter).
VB.NET
3. VB.NET – Program Structure
Before we study basic building blocks of the VB.Net programming language, let us look a bare
minimum VB.Net program structure so that we can take it as a reference in upcoming
chapters.
• Namespace declaration
• A class or module
• Variables
• Comments
4
Let us look at a simple code that would print the words "Hello World":
Imports System
Module Module1
Sub Main()
Console.WriteLine("Hello World")
Console.ReadKey()
End Sub
End Module
When the above code is compiled and executed, it produces the following result:
Hello, World!
5
VB.NET
• The first line of the program Imports System is used to include the System
namespace in the program.
• The next line has a Module declaration, the module Module1. VB.Net is completely
object oriented, so every program must contain a module of a class that contains the
data and procedures that your program uses.
• Classes or Modules generally would contain more than one procedure. Procedures
contain the executable code, or in other words, they define the behavior of the class.
A procedure could be any of the following:
o Function
o Sub
o Operator
o Get
o Set
o AddHandler
o RemoveHandler
o RaiseEvent
• The next line ('This program) will be ignored by the compiler and it has been put to
add additional comments in the program.
• The next line defines the Main procedure, which is the entry point for all VB.Net
programs. The Main procedure states what the module or class will do when executed.
6
• The last line Console.ReadKey() is for the VS.NET Users. This will prevent the screen
from running and closing quickly when the program is launched from Visual Studio
.NET.
If you are using Visual Studio.Net IDE, take the following steps:
• Specify a name and location for your project using the Browse button, and then choose
the OK button.
• Click the Run button or the F5 key to run the project. A Command Prompt window
appears that contains the line Hello World.
You can compile a VB.Net program by using the command line instead of the Visual Studio
IDE:
• Open the command prompt tool and go to the directory where you saved the file.
• If there are no errors in your code the command prompt will take you to the next line
and would generate helloworld.exe executable file.