0% found this document useful (0 votes)
28 views

Chapter 3 - Introduction To

Uploaded by

aceygaming12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Chapter 3 - Introduction To

Uploaded by

aceygaming12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Chapter 3: Introduction to VB.

NET a case sensitive language like, C++, Java, and C# are case
sensitive language.
3.1 Introduction
Applications built using the VB.NET language can access
It’s a simple, multi-paradigm object-oriented
all libraries that help to execute a VB.NET program.
programming language used to create a variety
application; Windows, Web, and mobile applications VB.NET applications not only running on the window
built on the .NET Framework. operating system but can also run on Linux or Mac OS.

3.2 What is VB.NET 3.3 VB.NET Features

The VB.NET stands for Visual Basic. Network Enabled These are the following features that make it the most
Technologies. popular programming language.

It is a simple, high-level, object-oriented programming ▪ It is an object-oriented programming language


language developed by Microsoft in 2002. Unlike its following various OOP concepts such as
successor of Visual Basic 6.0, its implemented on the abstraction, encapsulation, inheritance e.t.c
Microsoft .NET framework. ▪ This language is used to design user interfaces
for window, mobile, and web-based applications.
Its supports OOPs concept, such as abstraction,
▪ Supports rapid application development tool kit.
encapsulation, inheritance, and polymorphism. It is not
This means the developer does not need to write
all the codes as various code can be automatically So, it is not actively
invoked from its libraries. maintained.
▪ It is not a case sensitive language like other A VB.NET uses the Visual Basic uses the VB-
languages such as C++, java, etc. Common Language Runtime environment.
▪ Supports he multithreading concept, in which Runtime (CLR)
you can do multiple tasks at the same time. component of .Net
▪ A Window Form enables us to inherit all existing Framework at runtime
functionality of form that can be used to create a It is a compiled language It is an Interpreter based
new form. So, in this way, it reduced the code language
complexity. It does not support It supports backward
▪ It is useful to develop web, window, and mobile backward compatibility. compatibility
applications. It is a type-safe language It is not a type-safe
3.4 VB.NET & Visual Basic language.

VB.NET Visual Basic In VB.NET, data is Data Connectivity and

It is a modern, fully VB is the predecessor of handled using the handling are done

object-oriented language VB.NET and was not an ADO.net protocol. through DAO, RDO, and

that replaced VB6. object-oriented language. ADO (ActiveX Data


Object) protocol
A Multithreaded It does not support the Dim x As Integer as C, Java, Python, C++,
application can be multithread concept Public x As Integer = 10 etc.
developed in VB.NET. int x;
3.5 VB.NET & C# int x = 10;

VB.NET C#
3.6 VB.NET & JAVA
It is a case insensitive It is a case sensitive
language. For example, language. For example," VB.NET Java
"A" and "a" are the same. A" and "a" are different. developed by the developed by Sun
VB.NET supports It supports only Microsystem. Microsystem and
structured and structured error currently owned by
unstructured error handling. Oracle
handling. uses CLR (Common It uses JVM (java virtual
Each statement does not Each statement is Language Runtime) at machine) at runtime.
end with a semicolon. terminated with a runtime to execute
semicolon (;) programs
Uses Simple English for It uses a simple It uses ADO.NET for It uses JDBC and ODBC for
defining the structure programming structure database connectivity. database connectivity
It uses LINQ to define It has no LINQ features to Refers to the name given to various programming
queries in .Net define queries. elements such as variable, function, class, or any other
It is not case sensitive It is a case sensitive user-defined elements in the program. An identifier
language. language. should be the combination of letter, digit, and
uses Microsoft Visual Uses various IDEs such as underscore. Still, the first character of the identifier or
studio for developing an Eclipse, NetBeans, IntellJ variable name should start with alphabet letter or
application. IDE that makes the underscore (_) of any length.
development process Rules for naming identifiers
more comfortable
1. The first character of an identifier must start
3.7 VB.NET & Keywords
with an alphabet/underscore, that could be
These are reserved word with special meanings in the followed by any sequence of digits (0-9), letter
compiler, whose meaning cannot be changed. or underscore.
Therefore, these keywords cannot be used as an 2. An identifier should not contain any reserved
identifier in VB.NET programming such as class name, keyword.
variable, function, module 3. The only special character allowed is the
3.8 VB.NET Identifiers underscore (_).
4. It should not start with any digit.
5. It should not more than 51 characters.
6. An identifier can contain two underscores, but Syntax:
should not be consecutive.
Dim Variable_Name as DataType
7. It should not have spaces in between
▪ VariableName defines the name of the variable
characters.
that you assign to store values.
3.9 VB.NET Comments

A comment is used to document the program so as to Datatype represents the name of the data type that

improve program readability. The compiler ignores you assign to a variable.

these comments therefore are not compiled with the


3.11 VB.NET & Data types
rest of the code. In VB.NET, we use ( ' ) symbol to
comment a statement. Data type Length
Boolean Depends on platform
3.10 VB.NET Data Type
Byte 1 byte
A data type informs the compiler the type of data or a Char 2 bytes
variable or function so that a variable can hold. When Date 8 bytes
we declare a variable, we have to tell the compiler what Decimal 16 bytes
type of data or value is allocated to different kinds of Double 8 bytes
variables to hold different amounts of space in Integer 4 bytes
computer memory. Long 8 bytes
Object Based on platform 4. CDate(expression): It is used to convert an
Sbyte 1 byte expression to a Date data type.
Short 2 bytes 5. CDbl(expression): It is used to convert an
Single 4 bytes expression into a Double data type.
String 6. CDec(expression): It is used to convert an
uninteger 4 bytes expression into a Decimal data type.
Ulong 8bytes 7. CInt(expression): It is used to convert an

ushort 2 bytes expression to an Integer data type.

3.12 Type Conversion Functions in VB.NET 8. CLng(expression): It is used to convert an


expression to a Long data type.
The following functions are available for converting
9. CObj(expression): It is used to convert an
from one data type to another
expression to an Object data type.
1. CBool(expression): It is used to convert an 10. CSByte(expression): It is used to convert an
expression into a Boolean data type. expression to an SByte data type.
2. CByte(expression): It is used to convert an 11. CShort(expression): It is used to convert an
expression to a Byte data type. expression to a Short data type.
3. CChar(expression): It is used to convert an 12. CSng(expression): It is used to convert an
expression to a Char data type. expression into a Single data type.
13. CStr(expression): It is used to convert an Variables must be declared before being used in a
expression into a String data type. program. This requires a variable name and data type
14. CUInt(expression): It is used to convert an followed by a Dim.
expression to a UInt data type.
Syntax:
15. CULng(expression): It is used to convert an
expression to a ULng data type. Dim [VariableName] As [Defined Data Type]
16. CUShort(expression): It is used to convert an
✓ Dim It is used to declare and allocate the space
expression into a UShort data type
for one or more variables in memory
3.13 VB.NET Variable and Constant
✓ Variable_Name defines the name of the variable
It’s a programmer’s memory location for storing a value to store the values
that keeps on changing during program execution. With ✓ As It is a keyword that allows you to define the
the help of variable, we can perform several operations data type in the declaration statement.
and manipulate data values in any programming ✓ Data Type It defines a data type that allows
language. variables to store data types such as Char, String,

3.14.1 VB.NET Variables Declaration Integer, Decimal, Long, etc.


✓ Value Assigns a value to the variable.

Some example are shown below:


Dim marks As Integer
Dim studentname As String Dim staffname As String
Dim Salary As Double
staffname = "David"
Dim marks, regno As Integer
Dim status As Boolean

To declare variables more than one variable in the Dim status As Boolean
same line, we must separate each variable with a status = True
comma.
We can also initialize a variable at the time of declaration:
Syntax

Dim regno As Integer = 1011345


Dim Variable_name1 As DataType1, variable_name2
Dim staffname As String = " David "
As DataType2, Variable_name3 As DataType3
3.14 VB.NET Constants
3.14.2 VB.NET Variable Initialization

After the declaration of a variable, we must assign a This are programmer’s memory locations that do not
value to the variable. The following syntax describes change value during program execution. They are also
the initialization of a variable
known as literals. These constants can be of any data
Variable_name = value
type, such as Integer, Double, String, Decimal, Single,
For example: character, enum, etc.
Dim regno As Integer
3.14.3 Declaration of Constants
regno = 1011345
In VB.NET, const is a keyword that is used to declare a Some examples are presented below
variable as constant. The Const statement can be used
1. Const size As Integer = 10
with module, structure, procedure, form, and class.
Const constname As datatype = value 2. Public Const name As String = "Wells"
3. Private Const PI As Double = 3.14
3.15 Scope of Variable in VB.NET
Item Name Descriptions

Variables scope refers to the extent to which a variable


Const It is a Const keyword to declare a
variable as constant. is accessible within the project. You can access it if the
variable is in a particular region or scope in the same
Constname It defines the name of the constant
variable to store the values. block. And if the variable goes beyond the region, its
scope expires.
As It is a keyword that allows you to
define the data type in the declaration
The following are the methods to represent the scope of
statement.
a variable in VB.NET.
Data Type It defines a data type that allows
variables to store data types such as 1. Procedure Scope
Char, String, Integer, Decimal, Long,
etc. 2. Module Scope
3. Public Scope
Value Assign a value to the variable as
constant.
3.15.1 Procedure (local) scope
A local variable is a type of variable defined within a procedure declaration can be declared the module-level

procedure scope, block, or function. It is available with variables. It means that these variables cannot be declared inside
any procedure block. Further, these variables are useful to share
a code inside the procedure, and it can be declared using
information between the procedures in the same module.
the Dim or static statement. These variables are not
Module-level variable remains in existence as long as the module
accessible from outside of the local method. is executed.

Local variables exist until the procedure in which they 3.15.3 Global (Public) Scope
are declared is executed. Once a procedure is executed,
They are variable that can be accessed globally in a
the values of its local variables will be lost, and the
program i.e. can be accessed by all the procedures or
resources used by these variables will be released. And
modules available in a program. This can be achieve
when the block is executed again, all the local variables
using the public keyword with a variable in a module or
are rearranged.
class at the top of the first procedure function. Global
3.15.2 Module Scope scope is also known as the Namespace scope.
Let's create a program that uses the global variable.
All existing procedures can easily identify a variable that is
declared inside a module sheet is called a module-level variable. 3.16 VB.NET Operators
The defined module variable is visible to all procedures within
In VB.NET programming, the Operator is a symbol that
that module only, but it is not available for other module's
is used to perform various operations on variables.
procedures. The Dim or private statement at the top of the first
An operator is a special symbol that tells the compiler to 7. Miscellaneous Operators
perform the specific logical or mathematical operation 8. Arithmetic Operators
on the data values. The data value itself (which can be 3.17.1. Arithmetic Operators in VB.NET
either a variable or a constant) is called an operand, and
operators Description
the Operator performs various operations on the
operand. ^ It is an exponentiation Operator that is
used to raises one operand to the
3.17 Different Types of VB.NET Operators
power of another operand.

VB.NET has different types of Operators that help in + The addition Operator is used to add
performing logical and mathematical operations on data numeric data, as well as concatenate
two string variables.
values. The Following are the different types of
Operators available in VB.NET - It is a subtraction Operator, which is
used to subtract the second operand
1. Arithmetic Operators from the first operand.
2. Comparison Operators
* The multiplication Operator is used to
3. Logical and Bitwise Operators
multiply the operands
4. Bit Shift Operators
/ It is a division Operator used to divide
5. Assignment Operators
one operand by another operand and
6. Concatenation Operators returns a floating-point result.
Mod It is a modulo (Modulus) Operator, operand is greater than the value of the
which is used to divide two operands right operand; If the condition is true, it
and returns only a remainder. returns TRUE; otherwise, it shows FALSE

3.17.2. Comparison Operators value.

They are used to compare the value of two variables or < It is a less than symbol which checks
whether the value of the left operand is less
operands for the various condition such as greater, less
than the value of the right operand; If the
than or equal, etc. and returns a Boolean value either condition is true, it returns TRUE; otherwise,

true or false based on the condition. it shows FALSE value.

>= It is greater than equal to which checks two


operator Description conditions whether the first operand is
greater than or equal to the second
= It checks whether the value of the two
operand; if yes, it returns TRUE; otherwise,
operands is equal; If yes, it returns a true
it shows False.
value, otherwise it shows False.
<= This symbol represents less than equal to
<> It is a Non-Equality Operator that checks
which determines the first operand is less
whether the value of the two operands is not
than or equal to the second operand, and if
equal; it returns true; otherwise, it shows
the condition is true, it returns TRUE;
false.
otherwise, it shows FALSE.

> A greater than symbol or Operator is used to


determine whether the value of the left
Is The Is Operator is used to validate whether Operator Description
the two objects reference the same variable
or object; If the test is true, it returns True; And The And Operator represents, whether both

otherwise, the result is False. In short, it the operands are true; the result is True.

checks the equality of the objects. An Is


Or It is an Or Operator that returns a true
Operator is also used to determine whether
value; if anyone operand is true from both
the object refers to a valid object.
the operands.

IsNot The IsNot Operator is similar to Is Operator,


Not The Not Operator is used to reverse the
except that the two object references the
logical condition. For example, if the
different object; if yes, the result is True;
operand's logic is True, it reveres the
otherwise, the result is False.
condition and makes it False.

Like The Like Operator is used to check the 3.17.4. Assignment Operators
pattern expression of string variable; And if
the pattern matched, the result is True; The Assignment Operators are used to assign the value
otherwise, it returns False. to variables in VB.NET.
3.17.3. Logical Operators
operator Description
They work with Boolean (true or false) conditions, and
if the conditions become true, it returns a Boolean true = It is a simple assignment Operator used
to assign a right-side operand or value
value.
to a left side operand.
+= An Add AND assignment Operator is \= It is a Divide AND assignment Operator,
used to add the value of the right which divides the left operand or value
operand to the left operand. And the with the right operand. And then, the
result is assigned to the left operand. result will be assigned to the left
operand (in integer-point division).
-= It is a Subtract AND assignment
Operator, which subtracts the right ^= It is an expression AND assignment
operand or value from the left operand. Operator, which raises the left operand
And then, the result will be assigned to or value to the right operand's power.
the left operand. And then, the result will be assigned to
the left operand.
*= It is a Multiply AND assignment
Operator, which multiplies the right &= It is a concatenate string assignment
operand or value with the left operand. Operator used to bind the right-hand
And then, the result will be assigned to string or variable with the left-hand
the left operand. string or variable. And then, the result
will be assigned to the left operand.
/= It is a Divide AND assignment Operator,
3.17.5. Concatenation Operators
which divides the left operand or value
with the right operand. And then, the In VB.NET, there are two concatenation Operators to
result will be assigned to the left
bind the operands
operand (in floating-point).
operator Description

& It is an ampersand symbol that is


used to bind two or more operand
together.

+ It is also used to add or


concatenate two number or string.

You might also like