本文介绍了QTP:如何从函数返回多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个函数,该函数可以从具有 2 个参数的函数返回多个值.

I'm trying to write a function which can return multiple values from a Function which is having 2 arguments.

例如:

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

这里这个名为 sample_function 的函数有 2 个参数,分别名为 arg1、arg2.当我在我的驱动程序脚本中调用这个函数时,比如 value = sample_function(2,Name_person),这个函数应该返回给我passenger, name1,age1,seatNumber 值.

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 使用 VBScript 来指定测试例程,因此我将其重新标记为 VBScript、VB,因为解决方案可能在 VBScript 中.

EDIT (LB): QTP uses VBScript to specify the test routines, so I retagged this to VBScript, VB because the solution is probably within VBScript.

推荐答案

一个简单的解决方案是返回一个数组:

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

这篇关于QTP:如何从函数返回多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 10:36