VBScript函数返回多个值 [英] VBScript function returning multiple values

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

问题描述

有没有办法在不使用

数组的情况下从函数返回多个值?字典对象会更好用吗?


-

Roland Hall

/ *这些信息是希望分发的将是有用的,但

没有任何保证;甚至没有适销性的暗示保证

或特定用途的适用性。 * /

Technet脚本中心 - http:// www .microsoft.com / technet / scriptcenter /

WSH 5.6文档 - http://msdn.microsoft.com/downloads/list/webdev.asp

MSDN Library - http://msdn.microsoft.com/library/default.asp

Is there a way to return multiple values from a function without using an
array? Would a dictionary object work better?

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp

推荐答案

" Roland Hall" <没有人@无处>在留言中写道

新闻:uJ ************* @ TK2MSFTNGP14.phx.gbl ...
"Roland Hall" <nobody@nowhere> wrote in message
news:uJ*************@TK2MSFTNGP14.phx.gbl...
有没有办法归还来自函数的多个值而不使用
数组?字典对象会更好用吗?

- Roland Hall
Is there a way to return multiple values from a function without using an
array? Would a dictionary object work better?

--
Roland Hall




s = Func()

Response.Write(s)


函数Func()

Const A =" a"

Const B =" ; b"

Const C =" c"

Func = A& "," &安培; B& "," &安培; C $ / $
结束功能


或者你认为CSV字符串是一个数组?


是否是Dcitionary "更好"取决于你想要什么?b $ b b ...



s = Func()
Response.Write(s)

Function Func()
Const A = "a"
Const B = "b"
Const C = "c"
Func = A & "," & B & "," & C
End Function

Or do you consider a CSV string an array?

Whether a Dcitionary would be "better" depends on what are you trying to
do...


Roland Hall schrieb:
Roland Hall schrieb:
有没有办法在不使用
数组的情况下从函数返回多个值?字典对象会更好用吗?
Is there a way to return multiple values from a function without using an
array? Would a dictionary object work better?




还有第三种方法:制作自己的数据类型通过定义一个具有您需要的所有值的类




Class MyClass

Public Value1

公共价值2

公共价值3

结束班级


函数ReturnMyClass

Dim c

set ReturnMyClass = new MyClass

ReturnMyClass.Vlalue1 =" 1"

ReturnMyClass.Vlalue2 =" 2"

结束功能


Jan



There is a third alternative: Make your own "datatype" by defining a class
that has all values you need:

Class MyClass
Public Value1
Public Value2
Public Value3
End Class

Function ReturnMyClass
Dim c
set ReturnMyClass = new MyClass
ReturnMyClass.Vlalue1 = "1"
ReturnMyClass.Vlalue2 = "2"
End Function

Jan


" McKirahan"在消息新闻中写道:0Z ******************** @ comcast.com ...

:Roland Hall <没有人@无处>在消息中写道

:新闻:uJ ************* @ TK2MSFTNGP14.phx.gbl ...

:>有没有办法从函数中返回多个值而不使用



:>阵列?字典对象会更好用吗?

:>

:> -

:> Roland Hall



:s = Func()

:Response.Write(s)



:函数Func()

:Const A =" a"

:Const B =" b"

:Const C =" c"

:Func = A& "," &安培; B& "," &安培; C $ / $
:结束功能



:或者你认为CSV字符串是数组吗?



:Dcitionary是否会更好。取决于你想要什么

:做...


感谢您的建议。


如果我将我的值作为字符串返回,那么我必须在我的

电话后解析它。

我的问题有点模糊。我试图传递两个返回值

,而不必使用数组,我不想打2个电话给

函数或调用2个函数。我其实想要命名对。这个=

一些值,那个=一些值


我通常使用的函数为:result = myFunc(param1,param2,...)

所以,我可以将多个参数传递给函数,但我只收到了

一个结果。我需要两个,将来可能还需要更多。


我的函数调用其他4个返回数组的函数,并且在点上我

有相当的内存中的数组很少。


我首先看了一个字典对象,但我不能让它工作。它会出现
要么不可能,要么就是我。我在VB 6中看到我可以返回

整个字典对象,但在vbscript中,看来我只能返回

键或项目,但不能同时返回两者。在VB 6中,''set''用于返回。 ASP

(vbscript)在我尝试的时候咬了一口灰尘。


Ex。


函数myFunc(param1) ,param2)

''创建字典对象

dim d

set d = CreateObject(...)

d.Add" string",value

...

set myFunc = d

end function

>
现在,myFunc = d.Keys或myFunc = d.Items工作正常,但我需要密钥和

项目值,或者我必须将它们编入索引。

所以,我开始阅读有关课程的内容,这似乎是正确的
方法。我只是想做更多的阅读。


-

Roland Hall

/ *这个信息是分发希望它有用,但是没有任何保证的b $ b;甚至没有适销性的暗示保证

或特定用途的适用性。 * /

Technet脚本中心 - http:// www .microsoft.com / technet / scriptcenter /

WSH 5.6文档 - http://msdn.microsoft.com/downloads/list/webdev.asp

MSDN Library - http://msdn.microsoft.com/library/default.asp
"McKirahan" wrote in message news:0Z********************@comcast.com...
: "Roland Hall" <nobody@nowhere> wrote in message
: news:uJ*************@TK2MSFTNGP14.phx.gbl...
: > Is there a way to return multiple values from a function without using
an
: > array? Would a dictionary object work better?
: >
: > --
: > Roland Hall
:
: s = Func()
: Response.Write(s)
:
: Function Func()
: Const A = "a"
: Const B = "b"
: Const C = "c"
: Func = A & "," & B & "," & C
: End Function
:
: Or do you consider a CSV string an array?
:
: Whether a Dcitionary would be "better" depends on what are you trying to
: do...

Thank you for your suggestion.

If I returned my values as a string, then I''d have to parse it after my
call.
My question was kind of vague. I was trying to pass two return values
without having to do it with an array and I didn''t want to make 2 calls to
the function or call 2 functions. I actually wanted named pairs. this=
some value, that= some value

I normally use functions as: result = myFunc(param1, param2, ...)
So, I can pass multiple parameters to the function but I was only receiving
one result. I have a need for two and possibly more in the future.

My function calls 4 other functions that do return arrays and at points I
have quite a few arrays in memory.

I first looked using a dictionary object but I can''t make it work. It
appears either it is not possible or it''s me. I saw in VB 6 I could return
the whole dictionary object but in vbscript, it appears I can only return
keys or items but not both. In VB 6, ''set'' is used on the return. ASP
(vbscript) bit the dust when I tried that.

Ex.

function myFunc(param1, param2)
'' create dictionary object
dim d
set d = CreateObject(...)
d.Add "string", value
...
set myFunc = d
end function

Now, myFunc = d.Keys or myFunc = d.Items works fine but I need the key and
item values or I have to index them.
So, I started reading about classes and that appears to be the right
approach. I''m just going to have more reading to do.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆