Posts: 18
Threads: 8
Joined: Dec 2009
Reputation:
0
12-04-2009, 04:34 PM
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
Posts: 36
Threads: 0
Joined: Dec 2009
Reputation:
0
12-04-2009, 04:41 PM
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
Posts: 18
Threads: 8
Joined: Dec 2009
Reputation:
0
12-04-2009, 04:56 PM
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
Posts: 36
Threads: 0
Joined: Dec 2009
Reputation:
0
12-04-2009, 05:04 PM
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
Posts: 18
Threads: 8
Joined: Dec 2009
Reputation:
0
12-04-2009, 05:36 PM
Hi Nil,
Thanks for the solution. It is working for strResult. Thanks again.
But how to get array values?
Regards,
Dinesh
Posts: 36
Threads: 0
Joined: Dec 2009
Reputation:
0
12-04-2009, 05:40 PM
(This post was last modified: 12-04-2009, 05:45 PM by nil.)
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
Posts: 49
Threads: 0
Joined: Nov 2009
Reputation:
0
12-04-2009, 05:46 PM
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.
Posts: 36
Threads: 0
Joined: Dec 2009
Reputation:
0
12-04-2009, 05:46 PM
(This post was last modified: 12-04-2009, 05:49 PM by nil.)
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
Posts: 18
Threads: 8
Joined: Dec 2009
Reputation:
0
12-04-2009, 06:06 PM
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
Posts: 36
Threads: 0
Joined: Dec 2009
Reputation:
0
12-04-2009, 06:12 PM
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.
|