SlideShare a Scribd company logo
Fundamentals
of
VB.Net
Dr.A.Bharathi Lakshmi,
Head and Assistant Professor of IT,
V.V.Vanniaperumal College for Women,
Virudhunagar.
Variables & Constants
 Variables
• Container that stores one or more values
• Name of the variable is unchanged.
• The value might change during execution.
 Constants
• Stores a constant value
• Name as well as the value cannot be changed during
execution.
Data Types
Data Types Description
Integer 32-bit number – numeric data
Long 64-bit number – numeric data
Short 16-bit number – numeric data
Byte ASCII characters value in a numeric format – binary data
Double Huge floating point numbers
Single Single precision floating point numbers
Decimal Very large floating point numbers
Boolean 16-bit number – Boolean values
Char Single character
DateTime Date and time information
String Alphanumeric data
Object Data of any type
Rules for Naming variables
 It must begin with a letter
 It cannot contain a period or an
identifier-type character
 It must not exceed 255 characters
 It must be unique within the scope.
Declaring Variables
 Dim statement is used to declare a
variable
Syntax
Dim VariableName [As type]
VariableName – name of the variable
type – data type
Declaration
Dim ivar
Dim svar=“Hello”
Dim ivar1,ivar2 as integer
Initialization
Dim ivar as Integer
ivar=25
New Keyword
 New keyword initialize the variables before using
them in the code
Examples
Dim Inta as Object
Inta= new Integer
dim Ints as new Integer()
Nothing Keyword
 Represents default value of any data type
 Re-initialize to its default value.
Examples
Dim Inta as Integer=20
Inta= inta+4
Inta=Nothing
Explicit declaration
 Can be declared implicitly as well as
explicitly
 Without declaring a variable ,if it is
used it is implicitly declared
Example
InCo=20*5
Option Explicit [on|off]
 On – explicit declaration
 Off – implicit declaration
 Default - on
Scope of a variables
 Defines it visiblity
 The part of the program that can
access the variable
 Based on scope, variables can be
divided into two types
• Procedure-level variables
• Module-level variables
Procedure-Level Variables
 Only accessed within the procedure
 Reffered as local variables
Sub MyPro()
Dim str as String
str=“Hello “
MsgBox(str)
End Sub
In this code the variable str can be used only within the
procedure MyPro()
Module-Level Variables
 Declared in the declaration section of the
Module.
 Module level variables are classified into
• Private – can be used within the modules
Private str as String
Sub MyPro()
str=“Hello “
End Sub
Sub display()
MsgBox(str)
End Sub
• Public – can be used across modules
Public str as String
Sub MyPro()
str=“Hello “
End Sub
Sub display()
MsgBox(str)
Declaring Constants
 Const Keyword is used to declare a
constant
Syntax
Const ConstantName [As type]
ConstantName – name of the constant
type – data type
Example
Const cd as integer =25
Dim ivar as Integer
if ivar =1000 then
MessageBox.show(“Discount offered is “ & cd &
“%”)
End if
Operators
 Perform actions on data.
 Actions can be classified as
• Mathematical Calculations
• Assigning values to variables
• Comparing data
• Binary calculations
Example
a=15+30
(+) sign is the mathematical operator
the added value will be stored in a using
assignment operator
Types of Operators
 Arithmetic
 Comparison
 Logical/bitwise
Arithmetic Operators
 Performs Mathematical calculations.
 The arithmetic Operators are
• + operator – Add two numebers
• - operator – Subtract two numbers
• * operator – Multiply two numbers
• / operator – divide two numbers returns
floating
point number
•  operator – divide two numbers returns
Integer
point number
• ^ operator – power for a specified number
x^y
Comparison Operators
 Used to compare the expression
 The operators are
• Relational Operators
 Compares two numerical values
 <.>,<=,>=,<> and =
 Returns a Boolean value
• Is Operators
 Compares two object references
 Check if they are identical
 Returns a Boolean value
• Like Operators
 Compares two strings
 Case sensitive
 Returns a Boolean value
Logical/Bitwise Operators
 Perform logical Operations
 Logical operators are
• And operator
• Or operator
• Not operator
• Xor operator
• AndAlso operator
• OrElse operator
Logical/Bitwise Operators
 And operator
• Performs AND logical operations
• Returns true only when all expressions return true.
Example
Dim res as Boolean
Dim x as Integer = 40
Dim y as Integer = 30
Dim z as Integer = 20
res=x>y and y>z ‘Returns true
res=y>x and y>z ‘Returns false
Logical/Bitwise Operators
 Or operator
• Performs OR logical operations
• Returns true if any one of the expressions
return true.
Example
Dim res as Boolean
Dim x as Integer = 40
Dim y as Integer = 30
Dim z as Integer = 20
res=x>y Or y>z ‘Returns true
res=y>x Or y>z ‘Returns true
Logical/Bitwise Operators
 Not operator
• Performs NOT logical operations.
• Negates the value of expression and returns the opposite
value.
• If true result will be false and vise versa.
Example
Dim res as Boolean
Dim x as Integer = 40
Dim y as Integer = 30
Dim z as Integer = 20
res=Not(x>y) ‘Returns False
res=Not(y>x) ‘Returns True
Logical/Bitwise Operators
 Xor operator
• Performs XOR logical operations
• Performs logical exclusion on two
expressions.
• Returns true if any one of the expression
returns true value
• Returns false if all the expression returns
same value
Example
Dim res as Boolean
Dim x as Integer = 40
Dim y as Integer = 30
Dim z as Integer = 20
res=x>y Xor y>z ‘Returns false
res=y>x Xor y>z ‘Returns true
Logical/Bitwise Operators
 AndAlso operator
• Performs AND logical operations
• If first expression returns false then the second expression
wont be evaluated
Example
Dim res as Boolean
Dim x as Integer = 40
Dim y as Integer = 30
Dim z as Integer = 20
res=x>y AndAlso y>z ‘Returns true
res=y>x AndAlso y>z ‘Returns false
Logical/Bitwise Operators
 OrElse Operator
• Performs OR logical operations
• If first expression returns true then the second expression
wont be evaluated.
Example
Dim res as Boolean
Dim x as Integer = 40
Dim y as Integer = 30
Dim z as Integer = 20
res=x>y OrElse y>z ‘Returns true
res=y>x OrElse y>z ‘Returns true
Operator Precedence
 Order of evaluation of expressions
 Order of precedence
• Arithmetic Operators
 ^
 * & /
 
 + & -
• Comparison Operators
 =
 <>
 < & >
 >=
 <=
 Like
 Is
• Logical/Bitwise Operators
 Not
 And & AndAlso
 Or & OrElse
Operator Precedence
Example
2+3*4+5
a)20 b)45 c) 17 d) none
7-8+5
a) 6 b) -5 c) -4 d) 4
Expressions
 Combination of operators and operands.
 The value of the expressions are calculated at the
time of execution.
 Three types of expressions
• Numeric
• Value Comparison
• Boolean
Expressions
 Numeric Expressions
• Returns numeric values
• Is calculated using operator precedence rules
Examples
Dim cel as Integer
Dim far as Integer = 90
cal= (5/9)* (far-32)
Expressions
 Value comparison expressions
• Compare values
• Comparison operators are used
Examples
if x>250 then
MessageBox.Show(“>250”)
else
MessageBox.Show(“<=250”)
end if
Expressions
 Boolean Expressions
• Evaluates a Boolean value
Examples
if pass=true then
MessageBox.Show(“pass”)
else
MessageBox.Show(“fail”)
end if
Conversions
 Assigns the value of a variable of a data type to a
variable of another data type.
 If the value of the integer variable is assign to a long
variable it is broadening
 If the value of the long variable is assign to an integer
variable it is narrowing
 Types
• Implicit – broadening
• Explicit – narrowing (type.parse())
Controlling Program Flow
• Decision statements
 Execute stmts. based on the condition
 If…Then
 If…Then…Else
 Select…Case
• Looping Statement
 While…End While
 Do…Loop
 For…Next
 For…Each…Next
Decision Statements
 If…Then
• To execute a block of code based on a certain
condition
Syntax
If <<condition>> Then
‘Statements to be executed
End If
Decision Statements
 If…Then…Else
• Same as If…Then
• Two blocks of code can be executed for true case as
well as for false case
Syntax
If <<condition>> Then
‘Execute Statements if condition is true
Else
‘Execute Statements if condition is false
End If
Decision Statements
 Select…Case Statement
• Execute a group of statements based on the
test expression
• Can be a single variable or complex
expression
Syntax
Select <<testvalue>>
‘Execute a set of statements
Case <<value1>>
‘Execute a set of statements
Case <<value2>>
‘Execute a set of statements
Case <<value3>>
‘Execute a set of statements
Case Else
‘Execute a set of statements
End Select
Looping Statements
 While…End While
• Set of statements will be executed until the condition
becomes false.
Syntax
While <<condition>>
‘Executes statements
End While
Looping Statements
 Do…Loop
• Same as while loop
• Executes the block of code first without evaluating the
condition
• Then the condition is evaluated
Syntax
do
‘Executes statements
Loop While <<condition>>
Looping Statements
 For…Next Statement
• Same as while…end while
• Block of code will be executed for a fixed number of
times.
Syntax
For <<varnam>>=<<start>> to <<end>> Step <<value>>
‘Executes statements
Next
Looping Statements
 For…Each…Next Statement
• Similar to For...Next statement
• Enables to traverse through a collection
such as an array or a row of a table.
Syntax
For each <<varnam>> In <<array name or collection>>
‘Executes statements
Next
Examples
Dim I as integer
For Each I in Arrnam
Console.WriteLine(arrnam(i))
Next

More Related Content

PPTX
Basic VB.Net & Ms. Acces Integration to creat database application by. Rizki...
PPTX
Unit 1 introduction to visual basic programming
PPS
Visual Basic Review - ICA
PPT
Vb.Net 01 To 03 Summary Upload
DOCX
VBS control structures for if do whilw.docx
PPTX
Operators , Functions and Options in VB.NET
PDF
vb.net.pdf
PDF
Vb net1
Basic VB.Net & Ms. Acces Integration to creat database application by. Rizki...
Unit 1 introduction to visual basic programming
Visual Basic Review - ICA
Vb.Net 01 To 03 Summary Upload
VBS control structures for if do whilw.docx
Operators , Functions and Options in VB.NET
vb.net.pdf
Vb net1

Similar to Fundamentals of .Net Programming concepts (20)

PPT
Ms vb
PPTX
Input output
DOCX
VBScript datatypes and control structures.docx
PPTX
Vb script final pari
PPT
Visual basic 6.0
PPT
Programming
PPTX
Input output
PPT
Ch (2)(presentation) its about visual programming
DOCX
Data types and operators in vb
PPTX
Excel 2016 VBA PPT Slide Deck - For Basic to Adavance VBA Learning
PDF
Visual Basics for Application
PPTX
CHAPTER 3- Lesson A
PPTX
Variable, constant, operators and control statement
PPTX
Variable, constant, operators and control statement
PPTX
01 Database Management (re-uploaded)
PDF
Ppt on visual basics
PPTX
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
PPT
Project in TLE
Ms vb
Input output
VBScript datatypes and control structures.docx
Vb script final pari
Visual basic 6.0
Programming
Input output
Ch (2)(presentation) its about visual programming
Data types and operators in vb
Excel 2016 VBA PPT Slide Deck - For Basic to Adavance VBA Learning
Visual Basics for Application
CHAPTER 3- Lesson A
Variable, constant, operators and control statement
Variable, constant, operators and control statement
01 Database Management (re-uploaded)
Ppt on visual basics
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
Project in TLE
Ad

More from BharathiLakshmiAAssi (20)

PPT
.Net IDE Components and Applications
PPT
.Net Controlling Program Flow Statements
PPTX
VB.net&OOP.pptx
PPTX
VB.netIDE.pptx
PPT
VB.Net-Introduction.ppt
PPT
File Allocation Methods.ppt
PPTX
Demand Paging.pptx
PPTX
Virtual Memory.pptx
PPTX
Knowing about Computer SS.pptx
PPSX
Parallel Computing--Webminar.ppsx
PPSX
PPSX
Iterative Algorithms.ppsx
PPSX
Intensity Transformation.ppsx
PPSX
MAtrix Multiplication Parallel.ppsx
PPSX
Web Designing.ppsx
PPSX
Graphics Designing-Intro.ppsx
PPSX
Intensity Transformation & Spatial Filtering.ppsx
PPSX
DIP Slide Share.ppsx
PPSX
Class Timetable.ppsx
PPSX
.Net IDE Components and Applications
.Net Controlling Program Flow Statements
VB.net&OOP.pptx
VB.netIDE.pptx
VB.Net-Introduction.ppt
File Allocation Methods.ppt
Demand Paging.pptx
Virtual Memory.pptx
Knowing about Computer SS.pptx
Parallel Computing--Webminar.ppsx
Iterative Algorithms.ppsx
Intensity Transformation.ppsx
MAtrix Multiplication Parallel.ppsx
Web Designing.ppsx
Graphics Designing-Intro.ppsx
Intensity Transformation & Spatial Filtering.ppsx
DIP Slide Share.ppsx
Class Timetable.ppsx
Ad

Recently uploaded (20)

PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Basic Mud Logging Guide for educational purpose
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
master seminar digital applications in india
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Insiders guide to clinical Medicine.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Cell Structure & Organelles in detailed.
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Lesson notes of climatology university.
VCE English Exam - Section C Student Revision Booklet
Anesthesia in Laparoscopic Surgery in India
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Basic Mud Logging Guide for educational purpose
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Complications of Minimal Access Surgery at WLH
human mycosis Human fungal infections are called human mycosis..pptx
Microbial diseases, their pathogenesis and prophylaxis
PPH.pptx obstetrics and gynecology in nursing
master seminar digital applications in india
Supply Chain Operations Speaking Notes -ICLT Program
Insiders guide to clinical Medicine.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Renaissance Architecture: A Journey from Faith to Humanism
Cell Structure & Organelles in detailed.
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Lesson notes of climatology university.

Fundamentals of .Net Programming concepts

  • 1. Fundamentals of VB.Net Dr.A.Bharathi Lakshmi, Head and Assistant Professor of IT, V.V.Vanniaperumal College for Women, Virudhunagar.
  • 2. Variables & Constants  Variables • Container that stores one or more values • Name of the variable is unchanged. • The value might change during execution.  Constants • Stores a constant value • Name as well as the value cannot be changed during execution.
  • 3. Data Types Data Types Description Integer 32-bit number – numeric data Long 64-bit number – numeric data Short 16-bit number – numeric data Byte ASCII characters value in a numeric format – binary data Double Huge floating point numbers Single Single precision floating point numbers Decimal Very large floating point numbers Boolean 16-bit number – Boolean values Char Single character DateTime Date and time information String Alphanumeric data Object Data of any type
  • 4. Rules for Naming variables  It must begin with a letter  It cannot contain a period or an identifier-type character  It must not exceed 255 characters  It must be unique within the scope.
  • 5. Declaring Variables  Dim statement is used to declare a variable Syntax Dim VariableName [As type] VariableName – name of the variable type – data type Declaration Dim ivar Dim svar=“Hello” Dim ivar1,ivar2 as integer Initialization Dim ivar as Integer ivar=25
  • 6. New Keyword  New keyword initialize the variables before using them in the code Examples Dim Inta as Object Inta= new Integer dim Ints as new Integer()
  • 7. Nothing Keyword  Represents default value of any data type  Re-initialize to its default value. Examples Dim Inta as Integer=20 Inta= inta+4 Inta=Nothing
  • 8. Explicit declaration  Can be declared implicitly as well as explicitly  Without declaring a variable ,if it is used it is implicitly declared Example InCo=20*5 Option Explicit [on|off]  On – explicit declaration  Off – implicit declaration  Default - on
  • 9. Scope of a variables  Defines it visiblity  The part of the program that can access the variable  Based on scope, variables can be divided into two types • Procedure-level variables • Module-level variables
  • 10. Procedure-Level Variables  Only accessed within the procedure  Reffered as local variables Sub MyPro() Dim str as String str=“Hello “ MsgBox(str) End Sub In this code the variable str can be used only within the procedure MyPro()
  • 11. Module-Level Variables  Declared in the declaration section of the Module.  Module level variables are classified into • Private – can be used within the modules Private str as String Sub MyPro() str=“Hello “ End Sub Sub display() MsgBox(str) End Sub • Public – can be used across modules Public str as String Sub MyPro() str=“Hello “ End Sub Sub display() MsgBox(str)
  • 12. Declaring Constants  Const Keyword is used to declare a constant Syntax Const ConstantName [As type] ConstantName – name of the constant type – data type Example Const cd as integer =25 Dim ivar as Integer if ivar =1000 then MessageBox.show(“Discount offered is “ & cd & “%”) End if
  • 13. Operators  Perform actions on data.  Actions can be classified as • Mathematical Calculations • Assigning values to variables • Comparing data • Binary calculations Example a=15+30 (+) sign is the mathematical operator the added value will be stored in a using assignment operator
  • 14. Types of Operators  Arithmetic  Comparison  Logical/bitwise
  • 15. Arithmetic Operators  Performs Mathematical calculations.  The arithmetic Operators are • + operator – Add two numebers • - operator – Subtract two numbers • * operator – Multiply two numbers • / operator – divide two numbers returns floating point number • operator – divide two numbers returns Integer point number • ^ operator – power for a specified number x^y
  • 16. Comparison Operators  Used to compare the expression  The operators are • Relational Operators  Compares two numerical values  <.>,<=,>=,<> and =  Returns a Boolean value • Is Operators  Compares two object references  Check if they are identical  Returns a Boolean value • Like Operators  Compares two strings  Case sensitive  Returns a Boolean value
  • 17. Logical/Bitwise Operators  Perform logical Operations  Logical operators are • And operator • Or operator • Not operator • Xor operator • AndAlso operator • OrElse operator
  • 18. Logical/Bitwise Operators  And operator • Performs AND logical operations • Returns true only when all expressions return true. Example Dim res as Boolean Dim x as Integer = 40 Dim y as Integer = 30 Dim z as Integer = 20 res=x>y and y>z ‘Returns true res=y>x and y>z ‘Returns false
  • 19. Logical/Bitwise Operators  Or operator • Performs OR logical operations • Returns true if any one of the expressions return true. Example Dim res as Boolean Dim x as Integer = 40 Dim y as Integer = 30 Dim z as Integer = 20 res=x>y Or y>z ‘Returns true res=y>x Or y>z ‘Returns true
  • 20. Logical/Bitwise Operators  Not operator • Performs NOT logical operations. • Negates the value of expression and returns the opposite value. • If true result will be false and vise versa. Example Dim res as Boolean Dim x as Integer = 40 Dim y as Integer = 30 Dim z as Integer = 20 res=Not(x>y) ‘Returns False res=Not(y>x) ‘Returns True
  • 21. Logical/Bitwise Operators  Xor operator • Performs XOR logical operations • Performs logical exclusion on two expressions. • Returns true if any one of the expression returns true value • Returns false if all the expression returns same value Example Dim res as Boolean Dim x as Integer = 40 Dim y as Integer = 30 Dim z as Integer = 20 res=x>y Xor y>z ‘Returns false res=y>x Xor y>z ‘Returns true
  • 22. Logical/Bitwise Operators  AndAlso operator • Performs AND logical operations • If first expression returns false then the second expression wont be evaluated Example Dim res as Boolean Dim x as Integer = 40 Dim y as Integer = 30 Dim z as Integer = 20 res=x>y AndAlso y>z ‘Returns true res=y>x AndAlso y>z ‘Returns false
  • 23. Logical/Bitwise Operators  OrElse Operator • Performs OR logical operations • If first expression returns true then the second expression wont be evaluated. Example Dim res as Boolean Dim x as Integer = 40 Dim y as Integer = 30 Dim z as Integer = 20 res=x>y OrElse y>z ‘Returns true res=y>x OrElse y>z ‘Returns true
  • 24. Operator Precedence  Order of evaluation of expressions  Order of precedence • Arithmetic Operators  ^  * & /   + & - • Comparison Operators  =  <>  < & >  >=  <=  Like  Is • Logical/Bitwise Operators  Not  And & AndAlso  Or & OrElse
  • 25. Operator Precedence Example 2+3*4+5 a)20 b)45 c) 17 d) none 7-8+5 a) 6 b) -5 c) -4 d) 4
  • 26. Expressions  Combination of operators and operands.  The value of the expressions are calculated at the time of execution.  Three types of expressions • Numeric • Value Comparison • Boolean
  • 27. Expressions  Numeric Expressions • Returns numeric values • Is calculated using operator precedence rules Examples Dim cel as Integer Dim far as Integer = 90 cal= (5/9)* (far-32)
  • 28. Expressions  Value comparison expressions • Compare values • Comparison operators are used Examples if x>250 then MessageBox.Show(“>250”) else MessageBox.Show(“<=250”) end if
  • 29. Expressions  Boolean Expressions • Evaluates a Boolean value Examples if pass=true then MessageBox.Show(“pass”) else MessageBox.Show(“fail”) end if
  • 30. Conversions  Assigns the value of a variable of a data type to a variable of another data type.  If the value of the integer variable is assign to a long variable it is broadening  If the value of the long variable is assign to an integer variable it is narrowing  Types • Implicit – broadening • Explicit – narrowing (type.parse())
  • 31. Controlling Program Flow • Decision statements  Execute stmts. based on the condition  If…Then  If…Then…Else  Select…Case • Looping Statement  While…End While  Do…Loop  For…Next  For…Each…Next
  • 32. Decision Statements  If…Then • To execute a block of code based on a certain condition Syntax If <<condition>> Then ‘Statements to be executed End If
  • 33. Decision Statements  If…Then…Else • Same as If…Then • Two blocks of code can be executed for true case as well as for false case Syntax If <<condition>> Then ‘Execute Statements if condition is true Else ‘Execute Statements if condition is false End If
  • 34. Decision Statements  Select…Case Statement • Execute a group of statements based on the test expression • Can be a single variable or complex expression Syntax Select <<testvalue>> ‘Execute a set of statements Case <<value1>> ‘Execute a set of statements Case <<value2>> ‘Execute a set of statements Case <<value3>> ‘Execute a set of statements Case Else ‘Execute a set of statements End Select
  • 35. Looping Statements  While…End While • Set of statements will be executed until the condition becomes false. Syntax While <<condition>> ‘Executes statements End While
  • 36. Looping Statements  Do…Loop • Same as while loop • Executes the block of code first without evaluating the condition • Then the condition is evaluated Syntax do ‘Executes statements Loop While <<condition>>
  • 37. Looping Statements  For…Next Statement • Same as while…end while • Block of code will be executed for a fixed number of times. Syntax For <<varnam>>=<<start>> to <<end>> Step <<value>> ‘Executes statements Next
  • 38. Looping Statements  For…Each…Next Statement • Similar to For...Next statement • Enables to traverse through a collection such as an array or a row of a table. Syntax For each <<varnam>> In <<array name or collection>> ‘Executes statements Next Examples Dim I as integer For Each I in Arrnam Console.WriteLine(arrnam(i)) Next