Showing posts with label QTP Useful Code. Show all posts
Showing posts with label QTP Useful Code. Show all posts

Monday, 8 August 2011

Count Number Of words in String/Document

str = "my name is pankaj"
words= Split(str," ")
MsgBoxUBound(words)+1
'In case If you have to count the number of word in Notepad then you can use the following approch .

Set np = CreateObject("scripting.filesystemobject")
Set onp = np.OpenTextFile("C:\Documents and Settings\sharmapa\Desktop\Blog.txt",1)
str = onp.ReadAll
words= Split(str," ")
MsgBoxUBound(words)+1

Friday, 5 August 2011

Get Transaction time of QTP Script

1.Using QTP feature StartTransaction and EndTransaction given in the Insert toolbar options

Services.StartTransaction "str"
msgbox "I"
msgbox "am"
msgbox "Learning"
msgbox "QTP"
Services.EndTransaction "str"

2.Using MercuryTimers Function and we can give any thing in place of time in the following code it will give total time taken in seconds . 

MercuryTimers("Time").Start
  msgbox "I"
msgbox "am"
msgbox "Learning"
msgbox "QTP"
  TimeTaken=MercuryTimers("Time").Elapsedtime
       msgbox TimeTaken

3.Using Vbs will not heve any dependency on QTP what we need to do over here is we just need to the Hour,minute and second from the time and manipulate it to get the total trasaction time .

StartHour = Hour(now)
StartMin = Minute(now)
StartSec = Second(now)
msgbox "I"
msgbox "am"
msgbox "Learning"
msgbox "QTP"

EndHour = Hour(now)
EndMin = Minute(now)
EndSec = Second(now)
StartingSeconds = (StartSec + (StartMin * 60) + (StartHour * 60))
EndingSeconds = (EndSec + (EndMin * 60) + (EndHour * 60))
CallTimeSeconds = EndingSeconds - StartingSeconds
MsgBox CallTimeSeconds

Monday, 1 August 2011

Delete Cookies


SystemUtil.Run "Control.exe","inetcpl.cpl"
Set objShell = CreateObject("Wscript.Shell")
Do Until Success = True
Success = objShell.AppActivate("Internet Properties")
Wait(1)
Loop
objShell.Sendkeys "%i"
Wait(1)
objShell.Sendkeys "{ENTER}"
Wait(1)
objShell.Sendkeys "%f"
Wait(1)
objShell.Sendkeys "%d"
Wait(1)
objShell.Sendkeys "{ENTER}"
Wait(4)
objShell.Sendkeys "{ENTER}"

Saturday, 30 July 2011

Get Character value and their count from a string


Dim str
dim inttemp

str = "7pankaj7868PANKAJ"
i=1
k=0
Do
            temp = mid(str,i,1)
If  temp="" Then
            Exit do
End If
ascii = asc(temp)
            If  (ascii >=97 and ascii <=122) or (ascii >=65 and ascii <=90)Then
                        k=k+1
inttemp = inttemp&temp
            End If

i=i+1
Loop
msgbox K
msgbox inttemp

Wednesday, 20 July 2011

Reverse the String without using StrReverse


Dim i
Dim iStrLen
Dim strOut
Dim strTmp
Dim strMyString
strString=("Please enter the string to be reversed:")
iStrLen = Len(strString)
For i = 0 To Len(strString) - 1
         strOut = Mid(strString, iStrLen - i, 1)
         strTmp = strTmp & strOut
Next
strMyString = strTmp
msgbox strMyString

Tuesday, 17 May 2011

Find the length of the string without using strlen() function :

str="abcde"
x=Mid(str,1,1)
For i=1 to 100
 pos=instr(str,x)
 pos=pos+1
 x=Mid(str,pos,1)
 Leng=pos-1

 If x="" Then
  Exit For
 End If
Next
Msgbox "Lenght of the string" & "=" & Leng