Micro Focus QTP (UFT) Forums
Statement that can return an expression to the calling function - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Statement that can return an expression to the calling function (/Thread-Statement-that-can-return-an-expression-to-the-calling-function)



Statement that can return an expression to the calling function - prabhu656656 - 08-26-2009

Is there a statement that can return an expression to the calling function or test in QTP like the RETURN function in WinRunner.


RE: Statement that can return an expression to the calling function - Saket - 08-26-2009

You will be able to return an expression from function by assigning to the same function like following example-
Code:
Function ChkReturn()
   ChkReturn = 50
End Function

and an expression can be returned from reusable by using ouput parameter


RE: Statement that can return an expression to the calling function - supputuri - 08-26-2009

Hi,
Here is the sample code and let me know if you need any more info.

Code:
'this function will return the value is true or false
msgbox  MyFunction()
Public Function MyFunction ()
   blnFlag = False
  If 1 = 1 Then
      blnFlag = True
  End If
  MyFunction = blnFlag
End Function



RE: Statement that can return an expression to the calling function - prabhu656656 - 08-26-2009

My exact question is as we have a 'Return' keyword in WinRunner which are used in fucntions. So is there any QTP equivalent fucntion/keyword for 'Return'.
My objective is to migrate a WR code to QTP code.

For eg:
Code:
public function func1(str var1)
{
auto var1
var1="abc"
if (a=0) then
return var1
else
msgbox "Bad luck"
}



RE: Statement that can return an expression to the calling function - Saket - 08-26-2009

you can use the same code in QTP, Only you need to replace return with func1
here is your QTP code
Code:
public function func1(var1)

var1="abc"
if (a=0) then
func1 = var1
else
msgbox "Bad luck"
end function



RE: Statement that can return an expression to the calling function - basanth27 - 08-26-2009

It is through Byref,

Code:
Function func1 (Byref var1)
auto var1
var1 = "abc"
End function
this will return the var1 value back as a variable. There is nothing called Return statement in Vbscript unlike Winrunner.


RE: Statement that can return an expression to the calling function - prabhu656656 - 08-26-2009

Thanks a lot for solving the above.

Mentioned below are few others for which I need help from your guys..

Could any one suggest the Equivalent QTP funtions for the below mentioned WR functions:

1. getvar - getvar Returns the value of a testing option/configuration parameter.
Examples: 1. old_t = getvar ("timeout"); 2. old_d = getvar ("delay");

2. match - finds the occurrence of a regular expression in a string. This function returns the location in the string at which the regular_expression is found. The value returned is the character position at which the regular expression starts.

3. treturn - The treturn statement is used when calling a test. It stops a called test and returns control to the calling test. It also provides a return value for the called test.

4. getenv - returns the value of any environment variable, as defined WinRunner runtime environment.
getenv function reads the current value of an environment variable.


RE: Statement that can return an expression to the calling function - basanth27 - 08-26-2009

Prabhu -
Stop posting duplicate posts in multiple Categories.The original Post can be found at https://www.learnqtp.com/forums/Thread-QTP-Equivalent-functions-for-WR-functions

Thread Hijack !!! Locked.