功能:传递多个值 [英] Functions: Passing multiple values

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

问题描述

你好:


我想要一个函数将三个变量返回给调用程序:

私有函数CalcTimes(ByVal iAddDays as Integer ,ByVal iAddHours为

整数,ByVal iAddMins为整数)作为数组


变量值在函数中计算。


调用程序最好将值接收到相同

名称的变量中。


喜欢:Me.CalcTimes(iAddDays,iAddHours,iAddMins)


进一步使用是...(新TimeSpan(iAddDays,iAddHours,iAddMins,0))


可以使用ParamArray参数吗?


As Array是否正确或是否为整数?

我是否需要在使用之前将CalcTimes声明为数组,或者它是否为

数组的定义是什么?


这对我来说有点混乱。

Balena的Prog-Vb ParamArray示例开始:

函数和(ParamArray ByVal args()As Integer)作为整数

Dim index As Integer

索引= 0到UBound(args)....


到目前为止,我收到调试错误。我尝试了一个返回声明:

返回CalcTimes(iAddDays,iAddHours,iAddMins)

我甚至不确定在这里使用return语句。无论如何,它立即在结束函数声明之前



对于懒惰感到抱歉。我早上5:36即将结束。

谢谢。


D.


-
http://www.dennisys.com/

Hello:

I want a function to return three variables to the calling procedure:

Private Function CalcTimes(ByVal iAddDays as Integer, ByVal iAddHours as
Integer, ByVal iAddMins as Integer) As Array

Variable values are calculated in the function.

Calling procedure receives the values preferably into variables of the same
name.

Like: Me.CalcTimes(iAddDays, iAddHours, iAddMins)

Further use is ...(New TimeSpan(iAddDays, iAddHours, iAddMins, 0))

Could use ParamArray Arguments?

Is As Array correct or should it be As Integer?
Do I need to declare CalcTimes as an array before it is used, or is it an
array by definition?

This is somewhat confusing to me.
Balena''s Prog-Vb ParamArray example begins:
Function Sum(ParamArray ByVal args() As Integer) As Integer
Dim index As Integer
For index = 0 to UBound(args)....

So far, I''m getting a debug error. I tried a return statement:
Return CalcTimes(iAddDays, iAddHours, iAddMins)
I''m not even sure about using a return statement here. It immediately
preceeds the End Function statement anyway.
Sorry about being lazy. 5:36AM is near end of the day for me.
Thanks.

D.

--
http://www.dennisys.com/

推荐答案

在yoursefl上轻松搞定


Public Sub myFunction(byRef iAddDays as Integer,byRef iAddHours as

整数,byRef iAddMins为整数)


使用Ref将通过引用传递,(只是传递指针)和

允许你修改变量并将所有3个传回去。


我不知道ParamArray ByVal Params()作为整数会做什么......永远不会看到ParamArray的b
之前。


-CJ

" Dennis D." < TE ** @ dennisys.com>在消息中写道

news:ub ************** @ tk2msftngp13.phx.gbl ...
Make it easy on yoursefl

Public Sub myFunction (byRef iAddDays as Integer, byRef iAddHours as
Integer, byRef iAddMins as integer)

Useing Ref will pass by reference, (just passing the "pointer" in) and
allow you to modify the variables and pass all 3 back.

I have no idea what ParamArray ByVal Params() as Integer will do... never
seen ParamArray before.

-CJ
"Dennis D." <te**@dennisys.com> wrote in message
news:ub**************@tk2msftngp13.phx.gbl...
你好:

我想要一个函数将三个变量返回到调用过程:

私有函数CalcTimes(ByVal iAddDays as Integer,ByVal iAddHours as
Integer,ByVal iAddMins as Integer)As数组

变量值在函数中计算。

调用过程最好将值接收到
同名变量中。

喜欢:Me.CalcTimes(iAddDays,iAddHours,iAddMins)

进一步使用是...(New TimeSpan(iAddDays,iAddHours,iAddMins,0))

可以使用ParamArray参数?

As数组是否正确或者是否为整数?
我是否需要在使用CalcTimes之前将其声明为数组,或者根据定义它是否为数组?

这对我来说有点混乱。
Balena的Prog-Vb ParamArray示例开始:
函数Sum(ParamArray ByVal args()As Integer)A s整数
Dim index As Integer
对于index = 0到UBound(args)....

到目前为止,我收到调试错误。我尝试了一个返回声明:
返回CalcTimes(iAddDays,iAddHours,iAddMins)
我甚至不确定在这里使用return语句。无论如何它立即在End Function语句之前。
抱歉懒惰。 5:36 AM对我来说已接近结束。
谢谢。

D.

-
http://www.dennisys.com/
Hello:

I want a function to return three variables to the calling procedure:

Private Function CalcTimes(ByVal iAddDays as Integer, ByVal iAddHours as
Integer, ByVal iAddMins as Integer) As Array

Variable values are calculated in the function.

Calling procedure receives the values preferably into variables of the same name.

Like: Me.CalcTimes(iAddDays, iAddHours, iAddMins)

Further use is ...(New TimeSpan(iAddDays, iAddHours, iAddMins, 0))

Could use ParamArray Arguments?

Is As Array correct or should it be As Integer?
Do I need to declare CalcTimes as an array before it is used, or is it an
array by definition?

This is somewhat confusing to me.
Balena''s Prog-Vb ParamArray example begins:
Function Sum(ParamArray ByVal args() As Integer) As Integer
Dim index As Integer
For index = 0 to UBound(args)....

So far, I''m getting a debug error. I tried a return statement:
Return CalcTimes(iAddDays, iAddHours, iAddMins)
I''m not even sure about using a return statement here. It immediately
preceeds the End Function statement anyway.
Sorry about being lazy. 5:36AM is near end of the day for me.
Thanks.

D.

--
http://www.dennisys.com/





从函数中获取多个返回值的简单方法是使用ByRef

参数。例如:


次CalcTimes(ByRef i As Integer,ByRef j As Integer,ByRef k As Integer)

i = 40

j = 49

k = 39

End Sub


Dim a,b,c As Integer

CalcTimes(a,b,c)


通话结束后,a,b& c将全部具有CalcTimes设定的值。


我希望这是你想要的。


Dennis D. ; < TE ** @ dennisys.com>在留言中写道

news:ub ************** @ tk2msftngp13.phx.gbl ...

你好:


我想要一个函数将三个变量返回给调用程序:

私函数CalcTimes(ByVal iAddDays as Integer,ByVal iAddHours as

整数,ByVal iAddMins as Integer)As Array


变量值在函数中计算。


调用过程接收值最好是变成相同的

名称的变量。


喜欢:Me.CalcTimes(iAddDays,iAddHours,iAddMins)


进一步使用是...(新TimeSpan(iAddDays,iAddHours,iAddMins,0))


可以使用ParamArray参数吗?


As Array是正确的还是整数?

我是否需要在使用之前将CalcTimes声明为数组,或者根据定义是否为
数组? br />

这对我来说有点混乱。

Balena的Prog-Vb ParamArray示例开始s:

函数和(ParamArray ByVal args()As Integer)作为整数

Dim index As Integer

索引= 0到UBound( args)....


到目前为止,我收到了一个调试错误。我尝试了一个返回声明:

返回CalcTimes(iAddDays,iAddHours,iAddMins)

我甚至不确定在这里使用return语句。无论如何,它立即在结束函数声明之前



对于懒惰感到抱歉。我早上5:36即将结束。

谢谢。


D.


-
http://www.dennisys.com/

Hi,
An easy way to get multiple return values from a function is to use ByRef
parameters. For example:

Sub CalcTimes (ByRef i As Integer, ByRef j As Integer, ByRef k As Integer)
i = 40
j = 49
k = 39
End Sub

Dim a, b, c As Integer
CalcTimes (a, b, c)

After the call, a, b & c will all have the values set by CalcTimes.

I hope this is what you are looking for.

"Dennis D." <te**@dennisys.com> wrote in message
news:ub**************@tk2msftngp13.phx.gbl...
Hello:

I want a function to return three variables to the calling procedure:

Private Function CalcTimes(ByVal iAddDays as Integer, ByVal iAddHours as
Integer, ByVal iAddMins as Integer) As Array

Variable values are calculated in the function.

Calling procedure receives the values preferably into variables of the same
name.

Like: Me.CalcTimes(iAddDays, iAddHours, iAddMins)

Further use is ...(New TimeSpan(iAddDays, iAddHours, iAddMins, 0))

Could use ParamArray Arguments?

Is As Array correct or should it be As Integer?
Do I need to declare CalcTimes as an array before it is used, or is it an
array by definition?

This is somewhat confusing to me.
Balena''s Prog-Vb ParamArray example begins:
Function Sum(ParamArray ByVal args() As Integer) As Integer
Dim index As Integer
For index = 0 to UBound(args)....

So far, I''m getting a debug error. I tried a return statement:
Return CalcTimes(iAddDays, iAddHours, iAddMins)
I''m not even sure about using a return statement here. It immediately
preceeds the End Function statement anyway.
Sorry about being lazy. 5:36AM is near end of the day for me.
Thanks.

D.

--
http://www.dennisys.com/


如果iAddDays,iAddHours和iAddmins是你要返回的值,你可以将
传递给它们,并且这些值的变化将反映出

程序返回。在这种情况下,您不需要将其定义为

函数 - 您可以将其定义为子。

如果您打算使用这3个变量经常 - 可能是很多

日期时间计算 - 你可能想要用3

变量定义一个结构,然后创建一个返回该结构的函数。

类似于:


private结构DateTimeStruct

dim iAddDays as Integer

dim iAddHours as Integer

dim iAddMins as Integer

结束结构


函数CalcTimes()as DateTimeStruct


,然后将其称为:

dim myStruct as DateTimeStruct = Me.CalcTimes


就在这些线上..


希望有所帮助..

Imran。


" Dennis D." < TE ** @ dennisys.com>在消息中写道

news:ub ************** @ tk2msftngp13.phx.gbl ...
If iAddDays, iAddHours and iAddmins are the values you are returning, you
can just pass them byref and the changes to these values will reflect ones
the procedure returns. In that case, you don''t need to define it as
function - you could just define it as a sub.
If you are going to be using those 3 variables often - probably for a lot of
date-time calculations - you might want to define a structure with the 3
variables and then create a function that returns that structure.
something like:

private Structure DateTimeStruct
dim iAddDays as Integer
dim iAddHours as Integer
dim iAddMins as Integer
end structure

function CalcTimes( ) as DateTimeStruct

and then call it as:
dim myStruct as DateTimeStruct = Me.CalcTimes

just along those lines..

hope that helps..
Imran.

"Dennis D." <te**@dennisys.com> wrote in message
news:ub**************@tk2msftngp13.phx.gbl...
你好:

我想要一个函数将三个变量返回到调用过程:

私有函数CalcTimes(ByVal iAddDays as Integer,ByVal iAddHours as
Integer,ByVal iAddMins as Integer)As数组

变量值在函数中计算。

调用过程最好将值接收到
同名变量中。

喜欢:Me.CalcTimes(iAddDays,iAddHours,iAddMins)

进一步使用是...(New TimeSpan(iAddDays,iAddHours,iAddMins,0))

可以使用ParamArray参数?

As数组是否正确或者是否为整数?
我是否需要在使用CalcTimes之前将其声明为数组,或者根据定义它是否为数组?

这对我来说有点混乱。
Balena的Prog-Vb ParamArray示例开始:
函数Sum(ParamArray ByVal args()As Integer)A s整数
Dim index As Integer
对于index = 0到UBound(args)....

到目前为止,我收到调试错误。我尝试了一个返回声明:
返回CalcTimes(iAddDays,iAddHours,iAddMins)
我甚至不确定在这里使用return语句。无论如何它立即在End Function语句之前。
抱歉懒惰。 5:36 AM对我来说已接近结束。
谢谢。

D.

-
http://www.dennisys.com/
Hello:

I want a function to return three variables to the calling procedure:

Private Function CalcTimes(ByVal iAddDays as Integer, ByVal iAddHours as
Integer, ByVal iAddMins as Integer) As Array

Variable values are calculated in the function.

Calling procedure receives the values preferably into variables of the same name.

Like: Me.CalcTimes(iAddDays, iAddHours, iAddMins)

Further use is ...(New TimeSpan(iAddDays, iAddHours, iAddMins, 0))

Could use ParamArray Arguments?

Is As Array correct or should it be As Integer?
Do I need to declare CalcTimes as an array before it is used, or is it an
array by definition?

This is somewhat confusing to me.
Balena''s Prog-Vb ParamArray example begins:
Function Sum(ParamArray ByVal args() As Integer) As Integer
Dim index As Integer
For index = 0 to UBound(args)....

So far, I''m getting a debug error. I tried a return statement:
Return CalcTimes(iAddDays, iAddHours, iAddMins)
I''m not even sure about using a return statement here. It immediately
preceeds the End Function statement anyway.
Sorry about being lazy. 5:36AM is near end of the day for me.
Thanks.

D.

--
http://www.dennisys.com/



这篇关于功能:传递多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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