How to return multiple values from QTP User defined 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming) +--- Thread: How to return multiple values from QTP User defined function (/Thread-How-to-return-multiple-values-from-QTP-User-defined-function) Pages:
1
2
|
How to return multiple values from QTP User defined function - dineshb - 12-04-2009 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' " 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 RE: How to return multiple values from QTP User defined function - nil - 12-04-2009 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 RE: How to return multiple values from QTP User defined function - dineshb - 12-04-2009 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 RE: How to return multiple values from QTP User defined function - nil - 12-04-2009 fine. pass Variables byref to the function Here is the Solution Code: function fnGetVal(Sql, intRowNo, arrRowVal() , strResult,byref ReturlValue1,byRef ReturnValue2) Use ReturnValue1,RetuenValue2 directly in your program RE: How to return multiple values from QTP User defined function - dineshb - 12-04-2009 Hi Nil, Thanks for the solution. It is working for strResult. Thanks again. But how to get array values? Regards, Dinesh RE: How to return multiple values from QTP User defined function - nil - 12-04-2009 Code: function fnGetVal(Sql, intRowNo, arrRowVal() , strResult,byref ReturlValue1,byRef ReturnValue2) Assign Return array to function name directly. For Example Code: 'Call to the function RE: How to return multiple values from QTP User defined function - v_selvam - 12-04-2009 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. RE: How to return multiple values from QTP User defined function - nil - 12-04-2009 Sorry ignore the prevoius one Code: 'Call to the function if Array is passed byRef the no need to declare globale variables Thanks ~Nilesh RE: How to return multiple values from QTP User defined function - dineshb - 12-04-2009 Hi Nil, Changed the code as below in Function and working fine. Code: fnGetVal=arrRows 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 RE: How to return multiple values from QTP User defined function - nil - 12-04-2009 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. |