Conditional Statements:
A) Condition:- To execute a code dependens on condition, we can use this statement.
Syntax:- IF condition Then
----------
----------
----------
End IF
B) else-IF condition:-
Syntax:- IF condition Then
----------
----------
Else
----------
----------
End IF
EX:- Write vbscript in QTP to check given number is even or not.
Option explicit
Dim a
a=Inputbox(“enter the number”)
IF a Mod 2=0 Then
Msgbox(“Even”)
Else
Msgbox(“odd”)
End if
To check multiple conditions , we can follow syntax,
IF condition 1 Then
---------
---------
Elseif condition 2 Then
---------
---------
Elseif condition 3 Then
---------
---------
Else
---------
---------
End if
In above syntax, “else” block will be execute all conditions was false.
EX:-1
To display grade of students dependence on total marks. Here grade A is when total marks >=800, B grade is <=800 & >=700, C grade is <700 & >=600, and D grade is <600.
Option explicit
Dim m
M=inputbox(“enter the total marks”)
If m>=800 then
Msgbox(“grade is A”)
Elseif m<800 and >=700
Msgbox(“grade is B”)
Elseif m<700 and >=600
Msgbox(“grade is C”)
Else
Msgbox(“grade iis D”)
End if
EX:-2
To display gross sal of emp dependence on basic sal. Here commission is 10% on basic salary, when basic sal >=30000, commission is 5% when basic sal <30000 & >=15000, commission is 200 Rs when basic sal <15000.
Gross sal=basics sal+ commission.
Option explicit
Dim bsal ,comm., gsal
bsal=inputbox(“enter the basic sal”)
if bsal>=30000 then
comm=bsal*10/100
elseif bsal<30000 and bsal>=15000
comm.=bsal*5/100
else
comm.=200
end if
gsal=bsal+comm.
Msgbox(gsal)
EX:-3
Write vbscript in qtp, To display maturity amount dependence on commission and fixed deposit amount. Here commission is 10% when Age of depositor >=60 years.In general commission is 8.5% for others.
Option explicit
Dim amt,comm,age,tamt
amt=InputBox("Enter the amount")
age=InputBox("Enter the Age")
If age>60 Then
Comm=amt*10/100
Else
Comm=amt*8.5/100
End if
tmt=amt+comm.
Msgbox(tamt)
No comments:
Post a Comment