QTP: How can I return multiple Values from a Function
qtp, vbscript
Solution
A straightforward solution would be to return an array:
function foo()
foo=array("Hello","World")
end function
x=foo()
MsgBox x(0)
MsgBox x(1)
If you happen to use the same batch of values more often than once, then it might pay to make it a user defined class:
class User
public name
public seat
end class
function bar()
dim r
set r = new User
r.name="J.R.User"
r.seat="10"
set bar=r
end function
set x=bar()
MsgBox x.name
MsgBox x.seat
Problem
I'm trying to write a function which can return multiple values from a Function which is having 2 arguments. eg: ``` function sample_function(arg1,arg2) ''#Some code................. passenger = list1(0) name1 = list1(1) age1 = list1(2) seatNumber = list1(3) ''#This is an Incomplete function... end function sample_function ``` Here this function named sample_function has 2 argument named arg1, arg2. When i call this function in my Driver Script like value = sample_function(2,Name_person), this function should return me passenger, name1,age1,seatNumber values. How can i achieve this? EDIT (LB): QTP uses VBScript to specify the test routines, so I retagged this to VBScript, VB because the solution is probably within VBScript.