Difference between Call Statement and normal Function Call in QTP
[Call] functionOrSubName [Argument(s)]
|
Example:
‘—-Function Definition
Function fnNoParam_NoReturnVal() msgbox “No Parameters & No Return Values” End Function ‘—-Function Call fnNoParam_NoReturnVal() Call fnNoParam_NoReturnVal() |
In this example, both the function calls behave in the same manner and display the text “No Parameters & No Return Values” in a message box.
b) Case where the function to be called has arguments but doesn’t return any value: In a normal function call, the user can pass the parameters with and without parentheses. i.e. both ‘fnFunction(param)’ & ‘fnFunction param’ would work. But if Call statement is used here, parentheses must be provided while passing the arguments, else QTP would throw a run-time error.
Example:
‘—-Function Definition
Function fnNoReturnVal(param) msgbox param End Function ‘—-Function Call Call fnNoReturnVal(“some parameter”) ‘displays message box |
Example:
‘—-Function Definition
Function fnReturnsVal() fnReturnsValue = “this string is returned back” End Function |
‘—-Function Call
str1 = fnReturnsVal() ‘returns value to str1 variable
‘str2 = Call fnReturnsVal() ‘runtime error
In this example, ‘str2 = Call fnReturnsVal()’ throws a runtime error as Call statement doesn’t allow us to capture function’s returned value.
If you enjoyed this article, you can join our blog to get free email updates directly in your inbox.
Pingback: QTP & VBScript | Writing Functions and Sub Procedures in QTP - Automation Repository()