VBDotNet Notes-Unit 1
VBDotNet Notes-Unit 1
VBDotNet Notes-Unit 1
.NET Framework
.NET Framework is one of the most widely used software development
environment. It is developed by Microsoft and it runs on Microsoft windows
operating system.
With .NET, Microsoft provides programmer, a single platform for developing
applications using different programming languages such as Visual Basic,
Visual C++, F#, C# and so on in an easy, secure and reliable way
Language Compilers (e.g. C#, VB.Net, J#) will convert the Code to Microsoft
Intermediate Language (MSIL) which in turn will be converted to Native Code
by JIT compiler of CLR. Thus CLR facilitates the interoperability between
different .Net Languages
CLR defines the Common Type System (CTS), which is a standard type system
used by all .Net languages. All .NET programming languages uses the same
representation for common Data Types, so CLR is a language-independent
runtime environment . The Common Language Runtime environment is also
referred to as a managed environment, because during the execution of a
program it also controls the interaction with the Operating System.
Functions of CLR
Converts MSIL code to Native Code
Exception handling
Type safety
Memory management (using the Garbage Collector)
Security
Thread execution support
Debugging
Improved performance
Language independency
Platform independency
Architecture independency
Windows Forms
Windows Form allows you to develop Windows based desktop applications that
users can install and run on their computers. The basic entity of a Windows
Form application is a form, which is a rectangular area on which you can place
various controls to design the UI of the application
ASP.NET and ASP.NET AJAX
ASP.NET is a Web development model which is used to develop interactive,
data-driven Web applications over the Internet
ASP.NET AJAX includes both client-side and server-side components that
allows developers to create web applications such that the applications do not
require complete reload of the page while making any modifications to the page
ADO.NET
ActiveX Data Objects.NET is the database technology of .net framework that is
used for working with data and databases of all types
.Net Remoting
NET Remoting is used to build distributed applications easily, whether
application components are all on one computer or spread out across the entire
world.
Every language provides its own keywords for Data Types but internally all the
languages which run under .NET framework use the classes and structures
available in CTS.
For example, C# has int Data Type and VB.Net has Integer Data Type. Hence a
variable declared as int in C# or Integer in vb.net, finally after compilation, use
the same structure Int32 from CTS.
INTRODUCTION TO VB.NET
Visual Basic .NET (VB.NET) is an object-oriented computer programming
language implemented on the .NET Framework.
Some of the features of VB.Net are
Boolean Conditions
Automatic Garbage Collection
Standard Library
Assembly Versioning
Properties and Events
Delegates and Events Management
Easy-to-use Generics
Indexers
Conditional Compilation
Simple Multithreading
Simple VB.Net Program
A VB.Net program basically consists of the following parts:
Namespace declaration
A class or module
One or more procedures
Variables
The Main procedure
Statements & Expressions
Comments
The following program displays the message “Hello World” in the Console
Window
Imports System
Module Module1
'This program will display Hello World
Sub Main()
Console.WriteLine("Hello World")
Console.ReadKey()
End Sub
End Module
Variables
Variable is a temporary storage location for data in your application. It can
hold the result of a specific calculation, information received from user at
runtime or piece of data that you want to display on a page
Constants
Constant is a meaningful name that takes place of a number or text string that
does not change throughout the execution of a program.
Constants are declared with “const” keyword as follow
const PI as Double = 3.1415
Benefits of constants
Increases the readability of code
Makes global changes easier to accomplish
Reduce programming mistakes
Boxing and UnBoxing
Boxing and unboxing are important concepts in VB.NET's type system. With
Boxing and Unboxing, one can link between value-types and reference-types by
allowing any value-type to be converted to and from object type.
Unboxing is just the opposite. When an object box is cast back to its original
value type, the value is copied out of the box and into the appropriate storage
location
Data Types
Data types specify the size and type of values that can be stored. In Visual
Basic, data types are classified according to whether a variable of a particular
type stores its own data or a pointer to the data. If it stores its own data it is
a value type; if it holds a pointer to data elsewhere in memory it is a reference
type.
`
Value Types
A data type is a value type if it holds the data within its own memory
allocation. Value types are of fixed length and stored on the stack. Value types
include the following:
All primitive data types
Integer Types –sbyte, byte, short ,ushort, int, uint, long, ulong
Floating point types – float, double, decimal
Char type
Boolean type
Structures
Enumerations
Integer Types
The Integer type is used to represent a whole number. Integer data types
include the following types.
Single Type
It is used to represent fractional number with seven decimal digits of precision.
Append F to treat numeric literal as Single
Double Type
It is used to represent fractional number with 15 decimal digits of precision.
Append R to treat numeric literal as Double
Decimal Type
It is more precise than single or double. It has 28 decimal digits of precision.
Append D to treat numeric literal as Decimal
Char Type
It is used to represent a single Unicode character. It is of 2 bytes in length.
Append c when initializing a char
Boolean Type
Boolean type represents the Boolean value true or false. It is assigned 16 bits.
Structure Type
The structure data type is used to define a composite date type.
Defining a Structure
Public Structure Point
Dim x as Integer
Dim x as Integer
End Structure
Accessing a Structure
Dim p as Point
p.x=100
p.y=200
Enum Type
The Enum type is used to represent a set of named constants
Example
Enum Direction
West
East
North
South
End Enum
Reference Type
A reference type contains a pointer to another memory location that holds the
data. Reference types are of variable length and stored on the heap. Reference
types include the following:
Object
String
Class
Interface
Delegate
Arrays
Object Type
The Object type is a predefined referenced type. It serves as the base class for
all predefined and user defined classes.
String Type
The String type is also a predefined reference type. It is used for creating and
manipulating strings. We can perform various operations on string, such as
copying, comparing, searching, concatenating and so on.
Classes
Classes provide the best approach to group together the logically related items
and functions that work on them
Interface
Interfaces are a collection of members, such as methods, delegates, events and
Properties which are to be implemented by classes
Delegates
Delegates are used to encapsulate a method with a specific signature. It is
similar to function pointer in C++.
Arrays
Arrays are used to store a fixed size sequential collection of elements of same
type.
Value type Reference type
Operators
An operator is a symbol that tells the compiler to perform specific
mathematical or logical manipulations. VB.Net is rich in built-in operators and
provides following types of commonly used operators:
Arithmetic Operators
Comparison Operators
Logical/Bitwise Operators
Bit Shift Operators
Assignment Operators
Concatenation Operators
Arithmetic Operators
Arithmetic operators are used in mathematical expressions. The following table
lists the arithmetic operators:
Logical/Bitwise Operators
Bitwise operator works on bits and performs bit-by-bit operation. Following
table shows all the logical operators supported by VB.Net.
Assume variable A holds Boolean value True and variable B holds Boolean
value False, then
OrElse
When the left hand side is true, the condition of right hand side is never
evaluated
A B A AndAlso B
Concatenation Operator
Concatenation Operators are used to join multiple strings into a single string.
There are two concatenation operators namely “+” and “&”
Assignment Operator
= operator is user for assignment. It also serves as comparison operator.
The following are the shortcut assignment operators provided by VB.Net
Addition x=x+6 x += 6
Subtraction x=x-6 x -= 6
Multiplication x=x*6 x *= 6
Division x=x/6 x /= 6
Exponentiation x=x^6 x ^= 6
Operator Precedence
Operator precedence determines the grouping of terms in an expression. This
affects how an expression is evaluated. Operators with the highest precedence
appear at the top of the table, those with the lowest appear at the bottom.
Within an expression, higher precedence operators will be evaluated first
Operator Precedence
() Parenthesis Highest
^ Exponentiation
- Unary negation
*,/
/ Integer division
Mod
+, -
<< , >>
All comparison operators (=, <>, <, <=, >, >=)
Not
And, AndAlso
Or, OrElse
Xor Lowest
The Control class defines properties, methods, and events, which are common
to all Windows Forms controls
Label Control
The Label control is one of the most commonly used windows Form controls.
Label controls are typically used to provide descriptive text for a control. For
example, you can use a Label to add descriptive text for a TextBox control to
inform the user about the type of data expected in the control.
You can limit the amount of text entered into a TextBox control by setting the
MaxLength property to a specific number of characters. Use the
CharacterCasing property to enable the user to type only uppercase, only
lowercase, or a combination of uppercase and lowercase characters into the
TextBox control.
Button Control
Buton control lets you generate a Click event; by handling the click event of a
button, you can make the user perform some action at the runtime. A Button
can be clicked by using the mouse, ENTER key, or SPACEBAR if the button
has focus.