SlideShare a Scribd company logo
Control Flow Functions In VbScript 
Conditional statements allows us to make decisions and to control the flow of execution of a 
script or one of its sections and accordingly repeat actions. 
Usage of VBScript Conditional statements in QTP: 
I) We use conditional statements to insert verification points. 
II) We can user conditional checks for error handling purpose also. 
VBScript mainly provides following 2 types of decision making statements : 
I) If ...Then Statement. 
II) Select Case Statement. 
 Simple If ( Single line without block) statement is Condition is True: 
Dim myDate 
myDate=#10/10/2014# 
if myDate < date then myDate =date+2 ' where current date is 10/13/2014 
msgbox myDate 
'O/P - 10/15/2014 
 Execute block of statements using Simple If 
Dim myDate 
myDate=#10/10/2014# 
if myDate < date then 
myDate =date+2 ' where current date is 10/13/2014 
msgbox myDate 
msgbox "Mindfire solutions" 
End If 
'O/P - 10/15/2014 
Mindfire solutions 
 IF ...Then...Else 
Dim a,b 
a=5 
b=20
If a > b Then 
Msgbox "a is Greater" 
Else 
msgbox "b is Greater" 
End If 
 If...Then...ElseIf..Else Statement 
Dim a 
a = -5 
If a > 0 Then 
Msgbox "a is a POSITIVE Number" 
ElseIf a < 0 Then 
Msgbox "a is a NEGATIVE Number" 
Else 
Msgbox "a is EQUAL than ZERO" 
End If 
 nested if statements 
Dim a 
a = 23 
If a > 0 Then 
Msgbox "The Number is a POSITIVE Number" 
If a = 1 Then 
Msgbox "The Number is Neither Prime NOR Composite" 
Elseif a = 2 Then 
Msgbox "The Number is the Only Even Prime Number" 
Elseif a = 3 Then 
Msgbox "The Number is the Least Odd Prime Number" 
Else 
Msgbox "The Number is NOT 0,1,2 or 3" 
End If 
ElseIf a < 0 Then 
Msgbox "The Number is a NEGATIVE Number" 
Else 
Msgbox "The Number is ZERO" 
End If 
'O/P - The Number is a POSITIVE Number 
The Number is NOT 0,1,2 or 3 
 Select Case statement 
Executes one of several groups of statements, depending on the value of an expression.
Dim num1, num2, operation 
num1=5 
num2=10 
operation= Lcase(InputBox ("Enter an operation")) 
Select Case operation 
Case "add" 
msgbox "res:" &(num1+num2) 
Case "sub" 
msgbox "res:" &(num1-num2) 
Case "div" 
msgbox "res:" &(num2/num1) 
Case Else 
msgbox "res:" &(num1*num2) 
End Select 
Using Control Structures to Make Code Repeat 
For…Next 
The first structure is often referred to as the For…Next loop. The syntax for this structure is 
For counter = start to finish [Step step] 
...code that gets repeated 
Next 
Example: 
' increment loop by 2 
Counter = 1 
Result = 0 
For Counter = 1 to 5 step 2 
Result=Result + Counter 
msgbox Result 
Next
'Example with Exit For 
For Counter=1 to 5 
If Counter=3 Then 
Exit for 
End If 
msgbox Counter 
Next 
Do…Loop 
The first loop structure you can use is the Do While… 
Loop structure. The basic syntax for this structure is 
Do While <Condition> 
….Code with in the loop for repetitive activity 
Loop 
Example: 
Counter = 1 
Do While Counter < 4 
Total =Inputbox("Please enter the total marks in numbers") 
If Total < 30 Then 
MsgBox "Fail" 
ElseIf Total >=30 and Total <=100 then 
Msgbox "Pass" 
Else 
Msgbox "Invalid Marks" 
End If
Counter = Counter + 1 
Loop 
Exit Do While loop: 
i = 0 
Do While i <= 100 
If i > 10 Then 
Exit Do ' Loop Exits if i>10 
End If 
msgbox("The Value of i is : " &i) 
i = i + 2 
Loop 
There is an another piece of DO ..Loop. Below is the syntax: 
Do 
….Code with in the loop for repetitive activity 
Loop Until condition 
Example: 
Counter = 1 
Do 
Total =Inputbox("Please enter the total marks in numbers") 
If Total < 30 Then 
MsgBox "Fail" 
ElseIf Total >=30 and Total <=100 then 
Msgbox "Pass" 
Else 
Msgbox "Invalid Marks" 
End If 
Counter = Counter + 1
Loop until Counter > 4 
Exit Do Until loop: 
i = 0 
Do 
i = i + 2 
If i > 10 Then 
Exit Do ' Loop Exits if i>10 
End If 
msgbox("The Value of i is : " &i) 
Loop Until i > 100 
For Each...Next statement - runs code for each item in a collection or each element of an array 
Example: 
Dim birds(2) 
birds(0)="parrot" 
birds(1)="Crow" 
birds(2)="Sparrow" 
For Each x In birds 
msgbox(x) 
Next 
While...Wend: Executes a series of statements as long as a given condition is True. 
Example: 
Dim Counter 
Counter = 0 ' Initialize variable. 
While Counter < 20 ' Test value of Counter. 
Counter = Counter + 1 ' Increment Counter. 
msgbox Counter 
Wend ' End While loop when Counter > 19.
Conditional statements in vb script

More Related Content

PPTX
VB Script
Satish Sukumaran
 
PPTX
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
PDF
Generics
Ravi_Kant_Sahu
 
PDF
Java Presentation For Syntax
PravinYalameli
 
PDF
JavaScript - Chapter 4 - Types and Statements
WebStackAcademy
 
PPTX
Constructor in java
Pavith Gunasekara
 
PDF
Java - Exception Handling Concepts
Victer Paul
 
VB Script
Satish Sukumaran
 
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
Generics
Ravi_Kant_Sahu
 
Java Presentation For Syntax
PravinYalameli
 
JavaScript - Chapter 4 - Types and Statements
WebStackAcademy
 
Constructor in java
Pavith Gunasekara
 
Java - Exception Handling Concepts
Victer Paul
 

What's hot (20)

PDF
Inheritance
Pranali Chaudhari
 
PDF
Loops and conditional statements
Saad Sheikh
 
PPT
Switch statements in Java
Jin Castor
 
PPTX
VB Function and procedure
pragya ratan
 
PPTX
Switch case in C++
Barani Govindarajan
 
PPTX
Brief History of JavaScript
Rifad Ainun Nazieb
 
PPTX
C# Access modifiers
Prem Kumar Badri
 
PPTX
This keyword in java
Hitesh Kumar
 
PPTX
Access modifier and inheritance
Dikshyanta Dhungana
 
PPTX
JavaScript Conditional Statements
Marlon Jamera
 
PPTX
Java byte code presentation
Mahnoor Hashmi
 
PDF
Counting i (slides)
IIUM
 
PPTX
Java
proximotechsoft
 
PDF
Java IO
UTSAB NEUPANE
 
PDF
jQuery for beginners
Arulmurugan Rajaraman
 
PDF
javascript objects
Vijay Kalyan
 
PPT
C# Exceptions Handling
sharqiyem
 
PPTX
Object Oriented Programming (OOP) Introduction
SamuelAnsong6
 
PPTX
Exception handling in Java
Abhishek Pachisia
 
PPTX
Exception Handling in object oriented programming using C++
Janki Shah
 
Inheritance
Pranali Chaudhari
 
Loops and conditional statements
Saad Sheikh
 
Switch statements in Java
Jin Castor
 
VB Function and procedure
pragya ratan
 
Switch case in C++
Barani Govindarajan
 
Brief History of JavaScript
Rifad Ainun Nazieb
 
C# Access modifiers
Prem Kumar Badri
 
This keyword in java
Hitesh Kumar
 
Access modifier and inheritance
Dikshyanta Dhungana
 
JavaScript Conditional Statements
Marlon Jamera
 
Java byte code presentation
Mahnoor Hashmi
 
Counting i (slides)
IIUM
 
Java IO
UTSAB NEUPANE
 
jQuery for beginners
Arulmurugan Rajaraman
 
javascript objects
Vijay Kalyan
 
C# Exceptions Handling
sharqiyem
 
Object Oriented Programming (OOP) Introduction
SamuelAnsong6
 
Exception handling in Java
Abhishek Pachisia
 
Exception Handling in object oriented programming using C++
Janki Shah
 
Ad

Viewers also liked (8)

PPT
Vb script
mcatahir947
 
PPT
VBscript
vikashraj2090
 
PPTX
Conditional statements
University of Potsdam
 
PPT
Intorudction into VBScript
Vitaliy Ganzha
 
DOCX
Audit Imp Q_ Bcom III Year_General & Computers
Palle Chandrika
 
PDF
Hand book for 6th semester B.Com Bangalore University
selfpotent
 
PDF
Vb script tutorial for qtp[1]
srikanthbkm
 
PPSX
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 
Vb script
mcatahir947
 
VBscript
vikashraj2090
 
Conditional statements
University of Potsdam
 
Intorudction into VBScript
Vitaliy Ganzha
 
Audit Imp Q_ Bcom III Year_General & Computers
Palle Chandrika
 
Hand book for 6th semester B.Com Bangalore University
selfpotent
 
Vb script tutorial for qtp[1]
srikanthbkm
 
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 
Ad

Similar to Conditional statements in vb script (20)

DOCX
VBS control structures for if do whilw.docx
Ramakrishna Reddy Bijjam
 
PDF
Vbscript
Deepthi Reddy
 
DOCX
Vb script tutorial
Abhishek Kesharwani
 
PDF
Vb script tutorial
Abhishek Kesharwani
 
PDF
Chap 4 c++
Venkateswarlu Vuggam
 
PPT
Chap 4 c++
Venkateswarlu Vuggam
 
PPT
ملخص البرمجة المرئية - الوحدة الرابعة
جامعة القدس المفتوحة
 
PDF
4th_Ed_Ch03.pdf
ShifatiRabbi
 
PPTX
Programming Fundamentals in Python - Selection Structure
Georgios Papadopoulos
 
PDF
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
GrejoJoby1
 
PPT
Java căn bản - Chapter6
Vince Vo
 
PDF
Chapter 3 Computer Programmingodp-1_250331_041044.pdf
surafiraol103
 
PDF
Solved Practice Problems For the C++ Exams
MuhammadTalha436
 
PDF
Pseudocode By ZAK
Tabsheer Hasan
 
PDF
C101-PracticeProblems.pdf
T17Rockstar
 
PDF
Practiceproblems(1)
Sena Nama
 
PPTX
POLITEKNIK MALAYSIA
Aiman Hud
 
PDF
Python for Machine Learning
Student
 
PDF
Chap 5 c++
Widad Jamaluddin
 
PDF
OIT 116 LOOPS AND CONDITION STATEMENTS.pdf
Carlos701746
 
VBS control structures for if do whilw.docx
Ramakrishna Reddy Bijjam
 
Vbscript
Deepthi Reddy
 
Vb script tutorial
Abhishek Kesharwani
 
Vb script tutorial
Abhishek Kesharwani
 
ملخص البرمجة المرئية - الوحدة الرابعة
جامعة القدس المفتوحة
 
4th_Ed_Ch03.pdf
ShifatiRabbi
 
Programming Fundamentals in Python - Selection Structure
Georgios Papadopoulos
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
GrejoJoby1
 
Java căn bản - Chapter6
Vince Vo
 
Chapter 3 Computer Programmingodp-1_250331_041044.pdf
surafiraol103
 
Solved Practice Problems For the C++ Exams
MuhammadTalha436
 
Pseudocode By ZAK
Tabsheer Hasan
 
C101-PracticeProblems.pdf
T17Rockstar
 
Practiceproblems(1)
Sena Nama
 
POLITEKNIK MALAYSIA
Aiman Hud
 
Python for Machine Learning
Student
 
Chap 5 c++
Widad Jamaluddin
 
OIT 116 LOOPS AND CONDITION STATEMENTS.pdf
Carlos701746
 

Recently uploaded (20)

PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
Trends in pediatric nursing .pptx
AneetaSharma15
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PDF
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PDF
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PPTX
Autodock-for-Beginners by Rahul D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Trends in pediatric nursing .pptx
AneetaSharma15
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
Autodock-for-Beginners by Rahul D Jawarkar.pptx
Rahul Jawarkar
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 

Conditional statements in vb script

  • 1. Control Flow Functions In VbScript Conditional statements allows us to make decisions and to control the flow of execution of a script or one of its sections and accordingly repeat actions. Usage of VBScript Conditional statements in QTP: I) We use conditional statements to insert verification points. II) We can user conditional checks for error handling purpose also. VBScript mainly provides following 2 types of decision making statements : I) If ...Then Statement. II) Select Case Statement.  Simple If ( Single line without block) statement is Condition is True: Dim myDate myDate=#10/10/2014# if myDate < date then myDate =date+2 ' where current date is 10/13/2014 msgbox myDate 'O/P - 10/15/2014  Execute block of statements using Simple If Dim myDate myDate=#10/10/2014# if myDate < date then myDate =date+2 ' where current date is 10/13/2014 msgbox myDate msgbox "Mindfire solutions" End If 'O/P - 10/15/2014 Mindfire solutions  IF ...Then...Else Dim a,b a=5 b=20
  • 2. If a > b Then Msgbox "a is Greater" Else msgbox "b is Greater" End If  If...Then...ElseIf..Else Statement Dim a a = -5 If a > 0 Then Msgbox "a is a POSITIVE Number" ElseIf a < 0 Then Msgbox "a is a NEGATIVE Number" Else Msgbox "a is EQUAL than ZERO" End If  nested if statements Dim a a = 23 If a > 0 Then Msgbox "The Number is a POSITIVE Number" If a = 1 Then Msgbox "The Number is Neither Prime NOR Composite" Elseif a = 2 Then Msgbox "The Number is the Only Even Prime Number" Elseif a = 3 Then Msgbox "The Number is the Least Odd Prime Number" Else Msgbox "The Number is NOT 0,1,2 or 3" End If ElseIf a < 0 Then Msgbox "The Number is a NEGATIVE Number" Else Msgbox "The Number is ZERO" End If 'O/P - The Number is a POSITIVE Number The Number is NOT 0,1,2 or 3  Select Case statement Executes one of several groups of statements, depending on the value of an expression.
  • 3. Dim num1, num2, operation num1=5 num2=10 operation= Lcase(InputBox ("Enter an operation")) Select Case operation Case "add" msgbox "res:" &(num1+num2) Case "sub" msgbox "res:" &(num1-num2) Case "div" msgbox "res:" &(num2/num1) Case Else msgbox "res:" &(num1*num2) End Select Using Control Structures to Make Code Repeat For…Next The first structure is often referred to as the For…Next loop. The syntax for this structure is For counter = start to finish [Step step] ...code that gets repeated Next Example: ' increment loop by 2 Counter = 1 Result = 0 For Counter = 1 to 5 step 2 Result=Result + Counter msgbox Result Next
  • 4. 'Example with Exit For For Counter=1 to 5 If Counter=3 Then Exit for End If msgbox Counter Next Do…Loop The first loop structure you can use is the Do While… Loop structure. The basic syntax for this structure is Do While <Condition> ….Code with in the loop for repetitive activity Loop Example: Counter = 1 Do While Counter < 4 Total =Inputbox("Please enter the total marks in numbers") If Total < 30 Then MsgBox "Fail" ElseIf Total >=30 and Total <=100 then Msgbox "Pass" Else Msgbox "Invalid Marks" End If
  • 5. Counter = Counter + 1 Loop Exit Do While loop: i = 0 Do While i <= 100 If i > 10 Then Exit Do ' Loop Exits if i>10 End If msgbox("The Value of i is : " &i) i = i + 2 Loop There is an another piece of DO ..Loop. Below is the syntax: Do ….Code with in the loop for repetitive activity Loop Until condition Example: Counter = 1 Do Total =Inputbox("Please enter the total marks in numbers") If Total < 30 Then MsgBox "Fail" ElseIf Total >=30 and Total <=100 then Msgbox "Pass" Else Msgbox "Invalid Marks" End If Counter = Counter + 1
  • 6. Loop until Counter > 4 Exit Do Until loop: i = 0 Do i = i + 2 If i > 10 Then Exit Do ' Loop Exits if i>10 End If msgbox("The Value of i is : " &i) Loop Until i > 100 For Each...Next statement - runs code for each item in a collection or each element of an array Example: Dim birds(2) birds(0)="parrot" birds(1)="Crow" birds(2)="Sparrow" For Each x In birds msgbox(x) Next While...Wend: Executes a series of statements as long as a given condition is True. Example: Dim Counter Counter = 0 ' Initialize variable. While Counter < 20 ' Test value of Counter. Counter = Counter + 1 ' Increment Counter. msgbox Counter Wend ' End While loop when Counter > 19.