Chapter 3 - Introduction To
Chapter 3 - Introduction To
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.
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 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
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
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
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
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
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,
otherwise, the result is False. In short, it the operands are true; the result is True.
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