Functions allow two types of parameter declaration.
1. ByVal 2. ByRef
ByVal: Using ByVal parameter we pass the values to the function and use the values within the function.
Any changes in the value will limit to the function.
ByRef: Using ByRef parameter we pass the reference of the parameter.
Any changes made to the values inside the functions will be accessible in function as well as calling script.
Note: ByRef parameter always be a variable name
Note: If parameter type is not specified QTP will consider as the ByRef parameter.
Ex: Function addition(Byval a,ByRef b)
b=b+1
msgbox b
End Function
k=10
l=20
Call addition(k,l)
msgbox k “returns 10
msgbox l “returns 21
Return values in Functions:
Declaring the parameters ByRef , we can returning values
Ex: Function Sample1(ByVal x,ByRef y)
x=x+1
y=y+1
sample1=x+y
msgbox x 'displays 11
msgbox y ' displays 21
End Function
k=10
l=20
val=sample1(k,l)
msgbox val 'displays 32
msgbox k ' displays 10
msgbox l ' displays 21
Note: Function name acts like a return variable and thus we can use function name for returning value.
Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com
1. ByVal 2. ByRef
ByVal: Using ByVal parameter we pass the values to the function and use the values within the function.
Any changes in the value will limit to the function.
ByRef: Using ByRef parameter we pass the reference of the parameter.
Any changes made to the values inside the functions will be accessible in function as well as calling script.
Note: ByRef parameter always be a variable name
Note: If parameter type is not specified QTP will consider as the ByRef parameter.
Ex: Function addition(Byval a,ByRef b)
b=b+1
msgbox b
End Function
k=10
l=20
Call addition(k,l)
msgbox k “returns 10
msgbox l “returns 21
Return values in Functions:
Declaring the parameters ByRef , we can returning values
Ex: Function Sample1(ByVal x,ByRef y)
x=x+1
y=y+1
sample1=x+y
msgbox x 'displays 11
msgbox y ' displays 21
End Function
k=10
l=20
val=sample1(k,l)
msgbox val 'displays 32
msgbox k ' displays 10
msgbox l ' displays 21
Note: Function name acts like a return variable and thus we can use function name for returning value.
Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com