Thursday, 16 July 2015

QTP SAMPLE PROGRAMS


1.   ‘Program to find the number of numbers and alphabets in a given string
string1 = inputbox(”enter the string”)
For i = 1 to len(string1)
no = mid(string1,i,1)
character = asc(no)
If character >= 48 and character = 65 and character = 97 and character <= 122Then
alpcount = alpcount+1
End If
Next
msgbox “the count of numbers are”&numcount
msgbox “the count of alphabets are”&alpcount

2.   Ques: How to retrieve number from alphanumeric value.
Ans: follow the below code for answer: —
Dim myvar1, myvar2, myText, muarray()
myText = “HE1L0″
For i = 1 to Len(myText)
If Asc(Mid(myText, i, 1)) >47 and Asc(Mid(myText, i, 1)) < 58 Then
myvar1 = myvar1 + Mid(myText, i, 1) + “,”
MsgBox myvar1
Else
myvar2 = myvar2 + Mid(myText, i, 1)
MsgBox myvar2
End If
Next

3.   How to retrieve number from alphanumeric value.
Public Function AlphaCount(ByVal oldstr)
Dim strlen,str,charactercount,numcount,objRegExpr
Set objRegExpr = New regexp
objRegExpr.Pattern = “[a-zA-Z]”
objRegExpr.Global = True
strlen=Len(oldstr)
For i=1 to strlen
str=Mid(oldstr,i,1)
Set colMatches = objRegExpr.Execute(str)
If colMatches.Count Then
charactercount=charactercount+1
Else
numcount=numcount+1
End If
Next
AlphaCount=charactercount
End Function
MsgBox(AlphaCount(”111Oracle123″))



No comments:

Post a Comment