SlideShare a Scribd company logo
5
Most read
6
Most read
13
Most read
control structure in visual basic
SESSION:-2023-24
I N D E X
Introduction to Control Structure
Control Structure are used to control the
flow of program’s execution. By default control
structure in a program are executed sequentially.
There are two types of control structure:-
 Decision-making Statement
 LOOPING STATEMENT0
There are four types of decision making
statement:-
(1) Simple if statement
(2) If-else statement
(3) Nested if statement
(4) Select case statement
SIMPLE IF STATEMENT
There is only one condition in the program, then
simple if statement is used.It has only the true block
of the statement.
Syntax:-
If(Condition) then
Statement block
End If
Example:-
If(average>40) then
MsgBox”Passed”
End If
The if else statement works like that of simple if statement. With the
difference that if you want to execute the false block differently then
if else statement is used.In this type of statement you can have one
block corresponding to the true condition and the other block
corresponding to the false condition.
Syntex:-
if(Condition) then
Statement block-1
Else
Statement block-2
End If
Example:-
If(average>40) then
MsgBox “Passed’
Else
MsgBox “Failed”
End If
NESTED IF STATEMENT
If you have more then two condition to be tested then another if statement is used in else part of the if
statement it is called nesting.
Syntex;-
If(Condition-1) then
Statement block-1
Else
If(Condition-2) then
Statement block-2
Else
If(Condition-3) then
Statement block-3
-
-
Else
Satement block-n
End If
End If
End If
END SUB
Dim average As Integer
average = Val(Text1.Text)
If (average > 75) Then
printf = "A"
Else
If (average > 65) Then
printf = "B"
Else
If (average > 55) Then
printf = "C"
Else
If (average > 45) Then
printf = "S"
Else
printf = "F"
End If
End If
End If
End If
End Sub
Example:-
SELECT CASE STATEMENT
The select case statement is used as an alternative of if then else for selectively
Executing one block of statement from among multiple block of statement.
Syntex:-
Select case Expression
Case Expression-1
Statement block-1
Case Expression-2
Statement block-2
-
-
-
Case Else
Statement block-n
End select
Conti....2...
Example:-
days = Val(Text1.text)
If Val(Text1.text) = 1 Then
MsgBox "Sunday"
Else
If Val(Text1.text) = 2 Then
MsgBox "Monday"
Else
If Val(Text1.text) = 3 Then
MsgBox "Tuesday"
Else
If Val(Text1.text) = 4 Then
MsgBox "Wednesday"
Else
If Val(Text1.text) = 5 Then
MsgBox "Thursday"
Else
If Val(Text1.text) = 6 Then
MsgBox "Friday"
Else
If Val(Text1.text) = 7 Then
MsgBox "Saturday"
Else
MsgBox "not weakday"
End If
End If
End If
End If
End If
End If
Looping Satetment
There are six type of looping statement in visual basic:-
(1)While wend loop
(2)Do while loop
(3)Do untill loop
(4)Do loop until
(5)For next loop
(6)For each... next loop
While wend loop:-
While wend loop execute a block of statement while condition is
true.
Syntex:-
While(Condition) then
Statement block
Wend
Example:-
Dim num as Integer
Num=0
While(num<=10)
Print num
Num=num+1
Wend
DO WHILE LOOP
Do while loop is exit control loop. Do while works with
comparison expression just as the if statement does.
Syntex:-
Do while(Condition) then
Statement block
Loop
Example:-
Dim i As Integer
i=0
Do while(i<10)
Print i
i=i+1
loop
DO UNTIL LOOP
Do while loop continues executing the body of the loop as long as
the comparision test is true.But do until loop executes the body
of the loop as long as the comparision test is false.
Syntex:-
Do until (Condition)
Statement block
Loop
Example:-
Dim i As Integer
i=0
Do until (i>10)
Print i
i=i+1
loop
The loop continues until the loop until statement. The comparision test
appears at the bottom of the loop. Hence, the body of the loop always
executes atleast once.The body of the loop executes more than once as long
as the comparision test stayes false.
Syntex:-
Do
Statement block
Loop until (Condition)
Example:-
Dim i As Integer
i=0
Do
Print i
i=i+1
loop until (i>10)
The for loop repeats for a specific number of
times.Hence,for is a Keyword, counter is a variable name &
value1,value2 are integer values. The block of statement
should be a valid VB statement.
Syntex:-
For counter=value1 To value2
Statement block
Next Counter
Example:-
For i=1 to 10
Print i
Next i
FOR EACH.....NEXT LOOP
For each...next loop repeats a group of statement for each
element in a collection of objects or in an array instead of
repeating the statement a specified number of time.(Collection
can be of objects or arrays)
Syntex:-
For Each object/array
VB statement
Next
Example:-
For each element in group
VB statement
Next element
CONTROL STRUCTURE IN VB

More Related Content

What's hot (20)

PPT
Class and object in C++
rprajat007
 
PPTX
Type casting in java
Farooq Baloch
 
PPTX
Vb.net ide
Faisal Aziz
 
PPTX
Dynamic memory allocation
Viji B
 
PPTX
Java package
CS_GDRCST
 
PPTX
Control structures in java
VINOTH R
 
PPTX
Inter Thread Communicationn.pptx
SelvakumarNSNS
 
PPTX
Software Process Models
Hassan A-j
 
PPT
Communication primitives
Student
 
PDF
Java threads
Prabhakaran V M
 
PPT
Character stream classes introd .51
myrajendra
 
PPT
Introduction to method overloading &amp; method overriding in java hdm
Harshal Misalkar
 
PPTX
Operators in java
Then Murugeshwari
 
PPT
Uml in software engineering
Mubashir Jutt
 
PPT
Control structure C++
Anil Kumar
 
PPTX
A Role of Lexical Analyzer
Archana Gopinath
 
PPTX
Data types in java
HarshitaAshwani
 
PPT
15. Transactions in DBMS
koolkampus
 
PPT
Looping statements in Java
Jin Castor
 
Class and object in C++
rprajat007
 
Type casting in java
Farooq Baloch
 
Vb.net ide
Faisal Aziz
 
Dynamic memory allocation
Viji B
 
Java package
CS_GDRCST
 
Control structures in java
VINOTH R
 
Inter Thread Communicationn.pptx
SelvakumarNSNS
 
Software Process Models
Hassan A-j
 
Communication primitives
Student
 
Java threads
Prabhakaran V M
 
Character stream classes introd .51
myrajendra
 
Introduction to method overloading &amp; method overriding in java hdm
Harshal Misalkar
 
Operators in java
Then Murugeshwari
 
Uml in software engineering
Mubashir Jutt
 
Control structure C++
Anil Kumar
 
A Role of Lexical Analyzer
Archana Gopinath
 
Data types in java
HarshitaAshwani
 
15. Transactions in DBMS
koolkampus
 
Looping statements in Java
Jin Castor
 

Similar to CONTROL STRUCTURE IN VB (20)

PPTX
BSc. III Unit iii VB.NET
Ujwala Junghare
 
PDF
VB PPT by ADI PART3.pdf
AdiseshaK
 
PDF
VB PPT by ADI PART3.pdf
Prof. Dr. K. Adisesha
 
DOC
Conditional statements in vb script
Nilanjan Saha
 
PPTX
Unit IV Array in VB.Net.pptx
Ujwala Junghare
 
PPTX
Data structures vb
nicky_walters
 
PDF
Conditional Statements & Loops
simmis5
 
PPT
AVB201.2 Microsoft Access VBA Module 2
Dan D'Urso
 
PPSX
Control Structures in Visual Basic
Tushar Jain
 
PPT
Vb (2)
Rajeev Sharan
 
PPT
30,31,32,33. decision and loop statements in vbscript
VARSHAKUMARI49
 
PPT
Visual basic 6.0
Aarti P
 
PPTX
Looping statements
Jaya Kumari
 
PDF
Do...Loop
Muhammad Al Fatih
 
PDF
Vb script tutorial
Abhishek Kesharwani
 
DOCX
Vb script tutorial
Abhishek Kesharwani
 
DOCX
VBS control structures for if do whilw.docx
Ramakrishna Reddy Bijjam
 
PPT
.Net Controlling Program Flow Statements
BharathiLakshmiAAssi
 
PPTX
Vb.net (loop structure)
Abhishek Pachisia
 
PPTX
Presentation on visual basic 6 (vb6)
pbarasia
 
BSc. III Unit iii VB.NET
Ujwala Junghare
 
VB PPT by ADI PART3.pdf
AdiseshaK
 
VB PPT by ADI PART3.pdf
Prof. Dr. K. Adisesha
 
Conditional statements in vb script
Nilanjan Saha
 
Unit IV Array in VB.Net.pptx
Ujwala Junghare
 
Data structures vb
nicky_walters
 
Conditional Statements & Loops
simmis5
 
AVB201.2 Microsoft Access VBA Module 2
Dan D'Urso
 
Control Structures in Visual Basic
Tushar Jain
 
30,31,32,33. decision and loop statements in vbscript
VARSHAKUMARI49
 
Visual basic 6.0
Aarti P
 
Looping statements
Jaya Kumari
 
Vb script tutorial
Abhishek Kesharwani
 
Vb script tutorial
Abhishek Kesharwani
 
VBS control structures for if do whilw.docx
Ramakrishna Reddy Bijjam
 
.Net Controlling Program Flow Statements
BharathiLakshmiAAssi
 
Vb.net (loop structure)
Abhishek Pachisia
 
Presentation on visual basic 6 (vb6)
pbarasia
 
Ad

More from classall (20)

PPT
E-mail used in most important part in daily life
classall
 
PPTX
Digital Marketing USING IN YOUR LIFE STYLE
classall
 
PPT
E -COMMERCE.ppt
classall
 
PPTX
operat in vb .pptx
classall
 
PPT
Tally_Tutor_1.ppt
classall
 
PPTX
networking
classall
 
PPTX
introduction to visual basic PPT.pptx
classall
 
PPTX
introduction to e-commerce.pptx
classall
 
PPT
E-Rdiagram.ppt
classall
 
PPTX
EDI presentation.pptx
classall
 
PPTX
control structure in visual basic
classall
 
PPT
b,Sc it data structure.ppt
classall
 
PPTX
SAVE WATER SAVE LIFE
classall
 
PPTX
MS OFFICE
classall
 
PPTX
MULTIMEDIA
classall
 
PPTX
GEETA2.pptx
classall
 
PPTX
GEETA1.pptx
classall
 
PPTX
GEETA.pptx
classall
 
PPT
राष्ट्रीय एकता 13.3.18.ppt
classall
 
PPTX
mmu.pptx
classall
 
E-mail used in most important part in daily life
classall
 
Digital Marketing USING IN YOUR LIFE STYLE
classall
 
E -COMMERCE.ppt
classall
 
operat in vb .pptx
classall
 
Tally_Tutor_1.ppt
classall
 
networking
classall
 
introduction to visual basic PPT.pptx
classall
 
introduction to e-commerce.pptx
classall
 
E-Rdiagram.ppt
classall
 
EDI presentation.pptx
classall
 
control structure in visual basic
classall
 
b,Sc it data structure.ppt
classall
 
SAVE WATER SAVE LIFE
classall
 
MS OFFICE
classall
 
MULTIMEDIA
classall
 
GEETA2.pptx
classall
 
GEETA1.pptx
classall
 
GEETA.pptx
classall
 
राष्ट्रीय एकता 13.3.18.ppt
classall
 
mmu.pptx
classall
 
Ad

Recently uploaded (20)

PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 

CONTROL STRUCTURE IN VB

  • 1. control structure in visual basic SESSION:-2023-24
  • 2. I N D E X
  • 3. Introduction to Control Structure Control Structure are used to control the flow of program’s execution. By default control structure in a program are executed sequentially. There are two types of control structure:-  Decision-making Statement  LOOPING STATEMENT0
  • 4. There are four types of decision making statement:- (1) Simple if statement (2) If-else statement (3) Nested if statement (4) Select case statement
  • 5. SIMPLE IF STATEMENT There is only one condition in the program, then simple if statement is used.It has only the true block of the statement. Syntax:- If(Condition) then Statement block End If Example:- If(average>40) then MsgBox”Passed” End If
  • 6. The if else statement works like that of simple if statement. With the difference that if you want to execute the false block differently then if else statement is used.In this type of statement you can have one block corresponding to the true condition and the other block corresponding to the false condition. Syntex:- if(Condition) then Statement block-1 Else Statement block-2 End If Example:- If(average>40) then MsgBox “Passed’ Else MsgBox “Failed” End If
  • 7. NESTED IF STATEMENT If you have more then two condition to be tested then another if statement is used in else part of the if statement it is called nesting. Syntex;- If(Condition-1) then Statement block-1 Else If(Condition-2) then Statement block-2 Else If(Condition-3) then Statement block-3 - - Else Satement block-n End If End If End If END SUB
  • 8. Dim average As Integer average = Val(Text1.Text) If (average > 75) Then printf = "A" Else If (average > 65) Then printf = "B" Else If (average > 55) Then printf = "C" Else If (average > 45) Then printf = "S" Else printf = "F" End If End If End If End If End Sub Example:-
  • 9. SELECT CASE STATEMENT The select case statement is used as an alternative of if then else for selectively Executing one block of statement from among multiple block of statement. Syntex:- Select case Expression Case Expression-1 Statement block-1 Case Expression-2 Statement block-2 - - - Case Else Statement block-n End select Conti....2...
  • 10. Example:- days = Val(Text1.text) If Val(Text1.text) = 1 Then MsgBox "Sunday" Else If Val(Text1.text) = 2 Then MsgBox "Monday" Else If Val(Text1.text) = 3 Then MsgBox "Tuesday" Else If Val(Text1.text) = 4 Then MsgBox "Wednesday" Else If Val(Text1.text) = 5 Then MsgBox "Thursday" Else If Val(Text1.text) = 6 Then MsgBox "Friday" Else If Val(Text1.text) = 7 Then MsgBox "Saturday" Else MsgBox "not weakday" End If End If End If End If End If End If
  • 11. Looping Satetment There are six type of looping statement in visual basic:- (1)While wend loop (2)Do while loop (3)Do untill loop (4)Do loop until (5)For next loop (6)For each... next loop
  • 12. While wend loop:- While wend loop execute a block of statement while condition is true. Syntex:- While(Condition) then Statement block Wend Example:- Dim num as Integer Num=0 While(num<=10) Print num Num=num+1 Wend
  • 13. DO WHILE LOOP Do while loop is exit control loop. Do while works with comparison expression just as the if statement does. Syntex:- Do while(Condition) then Statement block Loop Example:- Dim i As Integer i=0 Do while(i<10) Print i i=i+1 loop
  • 14. DO UNTIL LOOP Do while loop continues executing the body of the loop as long as the comparision test is true.But do until loop executes the body of the loop as long as the comparision test is false. Syntex:- Do until (Condition) Statement block Loop Example:- Dim i As Integer i=0 Do until (i>10) Print i i=i+1 loop
  • 15. The loop continues until the loop until statement. The comparision test appears at the bottom of the loop. Hence, the body of the loop always executes atleast once.The body of the loop executes more than once as long as the comparision test stayes false. Syntex:- Do Statement block Loop until (Condition) Example:- Dim i As Integer i=0 Do Print i i=i+1 loop until (i>10)
  • 16. The for loop repeats for a specific number of times.Hence,for is a Keyword, counter is a variable name & value1,value2 are integer values. The block of statement should be a valid VB statement. Syntex:- For counter=value1 To value2 Statement block Next Counter Example:- For i=1 to 10 Print i Next i
  • 17. FOR EACH.....NEXT LOOP For each...next loop repeats a group of statement for each element in a collection of objects or in an array instead of repeating the statement a specified number of time.(Collection can be of objects or arrays) Syntex:- For Each object/array VB statement Next Example:- For each element in group VB statement Next element