Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

# Vb scripting

633
views

Published on

QTP SAMPLE SCRIPTS - For Learners …

QTP SAMPLE SCRIPTS - For Learners

Published in: Technology

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
633
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
16
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. July 28, PADMAJA RAJANIKANTH--> QTP SCRIPTS EXAMPLE 2012 VB Script – Arithmetic OperatorsArithmetic operators are used for arithmetic operations or mathematicaloperations such as Addition, Subtraction, Multiplication and other kindsof operations. Please find the list of Operators with some examples foreasy understanding. Operator English Meaning Example Result + Add 5+2 7 - Subtract 5-2 3 * Multiply 5*2 10 / Floating Point Division 5/2 2.5 Integer Division 52 2 ^ Exponent 5^2 25 Mod Modulus 5 Mod 2 1 Example 1:  Adding (+) Function Sum (a, b, X) X= a+b End Function Sum 4, 5, C Print C  Answer: 9 Example 2:  Float Division (/) Function FloatDiv (a, b, c) c = a/b End Function FloatDiv 3, 4, X Print X  Answer: 0.75 FloatDiv 5, 4, X Print X  Answer: 1.25 Example 3:  Integer Division () Function Div (a, b, c) c = ab End Function Div 5, 4, X Print X  Answer: 1 Div 6, 4, X Print X  Answer: 1
• 2. July 28, PADMAJA RAJANIKANTH--> QTP SCRIPTS EXAMPLE 2012Example 4: Modulus (Mod)Function Module (a, b, c)c = a Mod bEnd FunctionModule 4, 6, XPrint X  Answer: 4Module 17, 3, XPrint X  Answer: 2Example 5: Subtraction (-)Function Subtract (a, b, c)c=a-bEnd FunctionSubtract 4, 6, XPrint X  Answer: -2Subtract 17, 3, XPrint X  Answer: 14Example 6: Exponent (^)Function Expo (a, b, c)c=a^bEnd FunctionExpo (17, 3, X)Print X  Answer: 4913Expo (3, 3, X)Print X  Answer: 27Example 6: Multiplication (*)Function Multi (a, b, c, z)z = (a+b)*cEnd FunctionMulti (2, 5, 7, X)Print X  Answer: 49Multi (5, 5, 10, X)Print X  Answer: 100
• 3. July 28, PADMAJA RAJANIKANTH--> QTP SCRIPTS EXAMPLE 2012Write a script to print prime numbers based on the user input forthe prime number limit?Using For Loop:Prm = InputBox ("Please Enter Number", "PrimeNumber Number", 34,120,120)For i = 2 to Prm-1y = Prm mod iIf y <>0 ThenNum = "PrimeNumber" & PrmElseNum = "This is not an Prime Num" &Prmi = PrmEnd IfNextPrint NumFunctions:Prime 199  Answer is Prime NumberFunction Prime(X)For i = 2 to X-1Modval = X mod IIf Modval <>0 ThenNum = “Num is Prime Number: "&XElseNum = "Num is Not a Prime Number: "&Xi=XEnd IfNextPrint NumEnd FunctionPrime 199Using Do while LoopX = CInt (InputBox ("Please enter number"))Count=0b=1Do while b <= XIf X mod b = 0 ThenCount = count + 1Msgbox countEnd If
• 4. July 28, PADMAJA RAJANIKANTH--> QTP SCRIPTS EXAMPLE 2012b= b+1LoopIf count = 2 Then Print X &" "& "Is a PrimeNumber"ElsePrint "Not a Prime Number"End IfWrite a script to print String in Reverse order.Using Len and Mid FunctionsFunction RevStrg(X)L = Len(X)For i = 1 to LZ = Mid(X, i,1)y = Z &yNextPrint yEnd FunctionRevStrg ("QTP") Answer is PTQUsing StrReverse FunctionFunction RevStrg (Str, Rev) Rev = StrReverse (Str)End FunctionRevStrg "QTP", RevstrgsPrint Revstrgs  Answer is PTQVerify whether the entered number is Armstrong or notNum = CInt (InputBox ("Please Enter Value"))For i = 1 to Len (Num)x = Mid (Num, i, 1)Y = CInt (x) ^3 + YNextIf Y = Num ThenReporter.ReportEvent micPass,"","The Entered Number is ArmstrongNumber:" &NUM &"and" &YElseReporter.ReportEvent micFail,"", "The Entered Number is not anArmstrong Number:"&NUM &"and" &YEnd If
• 5. July 28, PADMAJA RAJANIKANTH--> QTP SCRIPTS EXAMPLE 2012Scripting for Adding of 10 Digit NumberFunction SumNumber(x, Sum)For i = 1 to Len(x)Num = Mid(x, i, 1)Sum = Int (num) + Int (Sum)Msgbox SumNextReporter.ReportEvent micDone,"", SumEnd FunctionSumNumber 12345678910, TotalSumPrint TotalSum  Answer 46Using Do LoopX = Int (InputBox ("Please Enter Number"))Z = Len(X)i=1Do while i<=ZNum = Mid(X, i, 1)Sum = Int (num) + Int (Sum)i=i+1LoopPrint Sum  Answer 46Find the Factorial of given Numberx = Int (InputBox ("Please Enter Number"))z = Len(x)Fact=1i=1Do while i <=xFact=Fact * ii = i +1LoopPrint FactComparing two excel sheets and marking the matching cells withcolorSet oxls = CreateObject ("Excel. Application")oxls.Visible = TrueSet obk = oxls.Workbooks.Open ("G:LATESTBook1.xlsx")Set ws = obk.Worksheets
• 6. July 28, PADMAJA RAJANIKANTH--> QTP SCRIPTS EXAMPLE 2012row1= ws ("Sheet1").Usedrange.rows.countColumn1 = ws ("Sheet1").Usedrange.columns.countrow2= ws ("Sheet2").Usedrange.rows.countColumn2 = ws ("Sheet2").Usedrange.columns.countsheet2 = ws ("Sheet2").UsedRange.Cells.CountFor i = 1 to Column1For j = 1 to Row1x = ws ("Sheet1").cells (j, i)For k = 1 to Column2For l = 1 to Row2y= ws ("Sheet2").cells (l, k)If x = y Thenz = x &Vbnewline & zWs ("Sheet2").Cells (l, k).Font. Bold=TrueWs ("Sheet1").Cells (j, i).Interior.color = 65535End IfNextNextNextNext TO BE CONTINUED ------------