将未知数量的参数传递给函数 [英] pass unknown number of parameters to function

查看:67
本文介绍了将未知数量的参数传递给函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




只是想知道是否有人知道如何传递和枚举VB函数的未知

参数。我想创建一个Min / Max函数

可以:

a)取可变数量的参数

b)确定传递了多少参数对它来说

c)循环参数


PS。我不能使用阵列或收藏品


任何帮助表示赞赏

Neil

Hi,

Just wondering if any one knows a way to pass and enumerate an unknown
number of parameter to a VB function. I want to create a Min/Max functions
that can:
a) take an variable number of parameters
b) determine how many parameter are passed to it
c) loop through parameters

PS. I can''t use an array or collection

Any help appreciated
Neil

推荐答案

嗨Neil,


我认为ParmamArray是你问题的最佳答案


来自MSDN的功能页面是什么在下面的链接中引用。

\\\

公共函数CalcSum(ByVal ParamArray Args()As Double)As Double

Dim I As Integer

CalcSum = 0

如果Args.Length< = 0则退出函数''没有参数通过。

For I = 0到UBound(Args,1)

CalcSum + = Args(I)

下一个我

结束函数''返回最新值CalcSum。

该函数可以调用如下:


Dim ReturnedValue As Double

ReturnedValue = CalcSum(4,3 ,2,1)

''函数'的局部变量被赋予以下值:

''Args(0)= 4,Args(1) = 3,所以

on。 http://msdn.microsoft.com/library/de...en-us/vblr7/ht

ml / vakeyparamarray.asp


我希望这有帮助吗?


Cor

Hi Neil,

I think that ParmamArray is the best answer on your question

From MSDN in the function page what is referenenced in the link bellow.
\\\
Public Function CalcSum(ByVal ParamArray Args() As Double) As Double
Dim I As Integer
CalcSum = 0
If Args.Length <= 0 Then Exit Function '' No arguments passed.
For I = 0 To UBound(Args, 1)
CalcSum += Args(I)
Next I
End Function '' Returns latest value of CalcSum.
The function can be invoked as follows:

Dim ReturnedValue As Double
ReturnedValue = CalcSum(4, 3, 2, 1)
'' The function''s local variables are assigned the following values:
'' Args(0) = 4, Args(1) = 3, and so
on.http://msdn.microsoft.com/library/de...en-us/vblr7/ht
ml/vakeyparamarray.asp

I hope this helps?

Cor



只是想知道是否有人知道一种方法来传递和枚举VB函数的未知数量的参数。我想创建一个Min / Max函数,它可以:
a)获取可变数量的参数
b)确定传递给它的参数数量
c)循环参数

PS。我不能使用阵列或收藏品

任何帮助赞赏
Neil
Hi,

Just wondering if any one knows a way to pass and enumerate an unknown
number of parameter to a VB function. I want to create a Min/Max functions
that can:
a) take an variable number of parameters
b) determine how many parameter are passed to it
c) loop through parameters

PS. I can''t use an array or collection

Any help appreciated
Neil



Cor ,


正是我需要的,谢谢一百万

Neil


Cor Ligthert ; <无********** @ planet.nl>在消息中写道

新闻:O6 ************* @tk2msftngp13.phx.gbl ...
Cor,

Just what I needed, thanks a million

Neil

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O6*************@tk2msftngp13.phx.gbl...
嗨Neil,
我认为ParmamArray是你问题的最佳答案

从功能页面的MSDN中可以看到以下链接中的内容。
\\\公共函数CalcSum(ByVal ParamArray Args()As Double)As Double
Dim I As Integer
CalcSum = 0
如果Args.Length< = 0那么退出函数''没有参数通过。
对于I = 0到UBound(Args,1)
CalcSum + = Args(I)
Next I
End Function''返回CalcSum的最新值。这个函数可以调用如下:

Dim ReturnedValue As Double
ReturnedValue = CalcSum(4,3,2,1)
''函数'的本地变量被赋予以下值:
''Args(0)= 4,Args(1)= 3,所以

on。 http://msdn.microsoft.com/library/de...en-us/vblr7/ht ml / vakeyparamarray.asp

我希望这有帮助吗?

Hi Neil,

I think that ParmamArray is the best answer on your question

From MSDN in the function page what is referenenced in the link bellow.
\\\
Public Function CalcSum(ByVal ParamArray Args() As Double) As Double
Dim I As Integer
CalcSum = 0
If Args.Length <= 0 Then Exit Function '' No arguments passed.
For I = 0 To UBound(Args, 1)
CalcSum += Args(I)
Next I
End Function '' Returns latest value of CalcSum.
The function can be invoked as follows:

Dim ReturnedValue As Double
ReturnedValue = CalcSum(4, 3, 2, 1)
'' The function''s local variables are assigned the following values:
'' Args(0) = 4, Args(1) = 3, and so
on.http://msdn.microsoft.com/library/de...en-us/vblr7/ht ml/vakeyparamarray.asp

I hope this helps?

Cor



只是想知道是否有人知道一种向VB函数传递和枚举未知数量参数的方法。我想创建一个Min / Max
函数,它们可以:
a)获取可变数量的参数
b)确定传递给它的参数数量
c)循环参数

PS。我不能使用阵列或收藏品

任何帮助表示赞赏
Neil
Hi,

Just wondering if any one knows a way to pass and enumerate an unknown
number of parameter to a VB function. I want to create a Min/Max functions that can:
a) take an variable number of parameters
b) determine how many parameter are passed to it
c) loop through parameters

PS. I can''t use an array or collection

Any help appreciated
Neil




我喜欢这个小组;)


K.


" Cor Ligthert" <无********** @ planet.nl>在消息中写道

新闻:O6 ************* @tk2msftngp13.phx.gbl ...
I Love this Group ;)

K.

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O6*************@tk2msftngp13.phx.gbl...
嗨Neil,
我认为ParmamArray是你问题的最佳答案

从功能页面的MSDN中可以看到以下链接中的内容。
\\\公共函数CalcSum(ByVal ParamArray Args()As Double)As Double
Dim I As Integer
CalcSum = 0
如果Args.Length< = 0那么退出函数''没有参数通过。
对于I = 0到UBound(Args,1)
CalcSum + = Args(I)
Next I
End Function''返回CalcSum的最新值。这个函数可以调用如下:

Dim ReturnedValue As Double
ReturnedValue = CalcSum(4,3,2,1)
''函数'的本地变量被赋予以下值:
''Args(0)= 4,Args(1)= 3,所以

on。 http://msdn.microsoft.com/library/de...en-us/vblr7/ht ml / vakeyparamarray.asp

我希望这有帮助吗?

Hi Neil,

I think that ParmamArray is the best answer on your question

From MSDN in the function page what is referenenced in the link bellow.
\\\
Public Function CalcSum(ByVal ParamArray Args() As Double) As Double
Dim I As Integer
CalcSum = 0
If Args.Length <= 0 Then Exit Function '' No arguments passed.
For I = 0 To UBound(Args, 1)
CalcSum += Args(I)
Next I
End Function '' Returns latest value of CalcSum.
The function can be invoked as follows:

Dim ReturnedValue As Double
ReturnedValue = CalcSum(4, 3, 2, 1)
'' The function''s local variables are assigned the following values:
'' Args(0) = 4, Args(1) = 3, and so
on.http://msdn.microsoft.com/library/de...en-us/vblr7/ht ml/vakeyparamarray.asp

I hope this helps?

Cor



只是想知道是否有人知道一种向VB函数传递和枚举未知数量参数的方法。我想创建一个Min / Max
函数,它们可以:
a)获取可变数量的参数
b)确定传递给它的参数数量
c)循环参数

PS。我不能使用阵列或收藏品

任何帮助表示赞赏
Neil
Hi,

Just wondering if any one knows a way to pass and enumerate an unknown
number of parameter to a VB function. I want to create a Min/Max functions that can:
a) take an variable number of parameters
b) determine how many parameter are passed to it
c) loop through parameters

PS. I can''t use an array or collection

Any help appreciated
Neil




这篇关于将未知数量的参数传递给函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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