Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to return multiple values from QTP User defined function
#1
Solved: 11 Years, 4 Months, 3 Weeks ago
Hi, I am new in QTP. I have to use three return values of a function. I can store one value to function name say fnGetVal = intRowNo.

In below function I have to read values from MsAccess table & store it in array arrRowVal() , total rows count in intRowNo & pass/fail value in strResult. The function is in Library part, arrRowVal is declared before starting function as Dim arrRowVal()


Code:
function fnGetVal(Sql,  intRowNo,  arrRowVal() ,  strResult)

'-- code to read access table & store in array arrRowVal, count in intRowNo, result pass/fail in strEndResult.

End function


'===== call code
Code:
strSql="Select SrNo,Name from ABCtbl where Flag = '1' "
  strErrorMessage=fnGetVal(strSql, intCount, arrRowVal, strResult)

Note : I am not sure the parameter arrRowVal is correct to pass or not in fnGetVal. Getting General error if arrRowVal() is written.


The function is working fine , but how to get the values stored in intRowNo, arrRowVal() , strEndResult in call code script.

Thanks in advance.
Dinesh
Reply
#2
Solved: 11 Years, 4 Months, 3 Weeks ago
Hi Dinesh

why are you passing input parameters to the function expect SQL statement

Code:
function fnGetVal(Sql, intRowNo, arrRowVal() , strResult)

'-- code to read access table & store in array arrRowVal, count in intRowNo, result pass/fail in strEndResult.

End function

clearly specify

Thanks
Reply
#3
Solved: 11 Years, 4 Months, 3 Weeks ago
Hi Nil,
Because I have to use intRowNo for loop purpose, arrRowVal required to use in main script & strResult for If statement, eg if stResult = pass then "execute statements" else "execute statements".

Hope this may clear the purpose.
Thanks
Reply
#4
Solved: 11 Years, 4 Months, 3 Weeks ago
fine.

pass Variables byref to the function

Here is the Solution
Code:
function fnGetVal(Sql, intRowNo, arrRowVal() , strResult,byref ReturlValue1,byRef ReturnValue2)

'-- code to read access table & store in array arrRowVal, count in intRowNo, result pass/fail in strEndResult.
ReturnValue1="qqqq"
RetuenValue2="aaaa"
End function

Use ReturnValue1,RetuenValue2 directly in your program
Reply
#5
Solved: 11 Years, 4 Months, 3 Weeks ago
Hi Nil,
Thanks for the solution. It is working for strResult. Thanks again.
But how to get array values?

Regards,
Dinesh
Reply
#6
Solved: 11 Years, 4 Months, 3 Weeks ago
Code:
function fnGetVal(Sql, intRowNo, arrRowVal() , strResult,byref ReturlValue1,byRef ReturnValue2)

'-- code to read access table & store in array arrRowVal, count in intRowNo, result pass/fail in strEndResult.
ReturnValue1="qqqq"
RetuenValue2="aaaa"
fnGetVal=arrRows
End function

Assign Return array to function name directly.
For Example


Code:
'Call to the function
Arr=Mytest
msgbox Arr(0)


' Function Defination
Public function Mytest()
   Humm=Array(1,2,3,4)
End Function
Reply
#7
Solved: 11 Years, 4 Months, 3 Weeks ago
You can you the following ways.

1. Return an Array object for that function.
2. paas an array object with ByRef keyword.
3. Diclare a global variable and assign an arrray to it.
Reply
#8
Solved: 11 Years, 4 Months, 3 Weeks ago
Sorry ignore the prevoius one

Code:
'Call to the function
Arr=Mytest
msgbox Arr(0)


' Function Defination
Public function Mytest()
   Mytest=Array(1,2,3,4)
End Function


if Array is passed byRef the no need to declare globale variables

Thanks
~Nilesh
Reply
#9
Solved: 11 Years, 4 Months, 3 Weeks ago
Hi Nil,
Changed the code as below in Function and working fine.
Code:
fnGetVal=arrRows  

===== call code
strSql="Select SrNo,Name from ABCtbl where Flag = '1' "
strErrorMessage=fnGetVal(strSql, intCount, arrRowVal, strResult)

I have got the values for strResult & arrRowVal in main script.
The arrRowVal's  values are assigned to strErrorMessage.  
strErrorMessage(0) - display first value
strErrorMessage(1) - display second value...

I am not understandig that strErrorMessage is a variable which is converted in an array.
Why is it so? I guess whatever type of value assigned to a varible then the varisble get converted in that type. Please tell me this interpretaion is correct or wrong.

Thank you very much for giving me your valuable time. Thanks!
Dinesh
Reply
#10
Solved: 11 Years, 4 Months, 3 Weeks ago
Any variable declared in QTP ia a varient
if u assign an array to it behaves as an Array as it is varient type Variable.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  QTP/UFT - Storing Multiple Arrays In An Array Eitel13 0 1,830 07-17-2018, 04:37 PM
Last Post: Eitel13
  UFT 12.02 Compatibility for IE 11.0 : Fail to identify the defined Object Amruta_121 9 11,282 01-11-2016, 12:45 PM
Last Post: vinod123
  Childobject return wrong checkbox count.. VpnQTP 1 2,888 04-09-2015, 09:07 PM
Last Post: babu123
  Calling a Function in Function Library when function is defined in an Action jitenderkkr 0 3,034 11-27-2014, 12:53 PM
Last Post: jitenderkkr
  Does QTP supports to open same application multiple times!!!!! pkiran169 1 3,019 08-07-2013, 01:09 PM
Last Post: anil2u

Forum Jump:


Users browsing this thread: 1 Guest(s)