1.Action is a specific to QTP while functions are a generic thing which is a feature of VB Scripting. 2.Action have a object repository, Data table etc associated with it while a function can't. 3.A function is just lines of code with some/none parameters and a single return value while an action can have more than one input/output parameters.
Custom Search
Tuesday, September 21, 2010
Diff B/w Actions and Functions
Open a Google page without using systemUtil.Run command?
Dim wsh
Set Wsh = CreateObject("Wscript.Shell")
Wsh.run "iexplore google.com"
Set Wsh = CreateObject("Wscript.Shell")
Wsh.run "iexplore google.com"
Monday, September 20, 2010
write the code to reverse a string without using Strrev built in function.
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
--------------------Second Scenario-----------
MyStr = inputbox("Enter the String:")
nCnt = Len(MyStr)
For i = 1 to nCnt
RevStr = Mid(MyStr,i,1)&RevStr
Next
Msgbox RevStr
-------------Third Scenario---------------
Dim yourstr,r,letter,result
yourstr="Automation"
Set r=new regexp
r.pattern="[a-z 0-9 A-Z]"
r.global=true
set s=r.execute(yourstr)
For each i in s
result= i.value&result
Next
msgbox result
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
--------------------Second Scenario-----------
MyStr = inputbox("Enter the String:")
nCnt = Len(MyStr)
For i = 1 to nCnt
RevStr = Mid(MyStr,i,1)&RevStr
Next
Msgbox RevStr
-------------Third Scenario---------------
Dim yourstr,r,letter,result
yourstr="Automation"
Set r=new regexp
r.pattern="[a-z 0-9 A-Z]"
r.global=true
set s=r.execute(yourstr)
For each i in s
result= i.value&result
Next
msgbox result
what is the script to select 2 or more than 2 options from a listbox.
Browser().Page.().weblist().Select " "
Browser().Page.().weblist().Extendselect " "
by using extendselect method we can select more than one at a time from list box.
Browser().Page.().weblist().Extendselect " "
by using extendselect method we can select more than one at a time from list box.
How do you return two values from a function
result=example(2,3)
function example(a,b)
dim myarray(2)
myarray(0) = a+b
myarray(1)=a*b
example=myarray
end function
msgbox result(0)
msgbox result(1)
function example(a,b)
dim myarray(2)
myarray(0) = a+b
myarray(1)=a*b
example=myarray
end function
msgbox result(0)
msgbox result(1)
How do you return a value from a function
msgbox "returned value =" &example(2,3)
function example(a,b)
example = a+b
end function
function example(a,b)
example = a+b
end function
How to handle Dynamic Arrays?
Declaring an array with empty parentheses(without dimension subscripts) is called Dynamic arrays.
Ex: Public\Private\Dim ArrayName ( )
The ReDim statement is used to size or resize a dynamic array.
Using ReDim statement You can change the number of elements and dimensions in an array repeatedly.
Ex: 1 ) Dim X(10)
ReDim X(15)
Ex :2 ). Dim X(10, 10)
ReDim X(10, 15)
Here if your array has two or more dimensions, you can change the size of only the last dimension only.
NOTE: If you are using ReDim for changing the size or Dimensions of Dynamic array, it's erasing an existing data contained in the array. to avoid this you should use Preserve Keyword before the array name.
Ex: Dim X(10)
ReDim Preserve X(15)
Ex: Public\Private\Dim ArrayName ( )
The ReDim statement is used to size or resize a dynamic array.
Using ReDim statement You can change the number of elements and dimensions in an array repeatedly.
Ex: 1 ) Dim X(10)
ReDim X(15)
Ex :2 ). Dim X(10, 10)
ReDim X(10, 15)
Here if your array has two or more dimensions, you can change the size of only the last dimension only.
NOTE: If you are using ReDim for changing the size or Dimensions of Dynamic array, it's erasing an existing data contained in the array. to avoid this you should use Preserve Keyword before the array name.
Ex: Dim X(10)
ReDim Preserve X(15)
Subscribe to:
Posts (Atom)