Button_Click中的函数 [英] Functions within Button_Click

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

问题描述

我试图在

Button_Click事件中调用递归子例程。我怎么能这样做?


我试图创建一个单独的Function()但它不会

允许我使用我创建的任何变量

Button_Click事件。


有什么想法吗?


谢谢!

解决方案

文章< 94 ****************************** ****@microsoft.co m>,
mr********@hormel.com 说...

我试图在
Button_Click事件中调用递归子例程。我怎么能这样做?

我试图创建一个单独的Function()但它不会允许我使用我在
Button_Click事件中创建的任何变量。 / blockquote>


你能把变量传递给递归函数吗? GOSUB命令

未在VB.NET中实现,因此您无法使用它。如果有很多变量要通过,你可以尝试将它们放在一个结构中。


-

Patrick Steele

Microsoft .NET MVP
http:// weblogs.asp.net/psteele


Matt,

这是一项家庭作业吗?

我试图创建一个单独的Function(),但它不会允许我使用我在
Button_Click事件中创建的任何变量。
你会传递变量将函数作为参数,就像任何其他函数或子函数一样。或者,您可以声明变量。

班级本身。


你尝试过类似的东西:


Private Sub Button_Click(... )

Dim x As Integer = 1000

Dim y As String

MyFunction(x,y)

End Sub


私函数MyFunction(ByVal x As Integer,ByVal y As String)

如果x< = 0则退出函数

MyFunction(x - 1,y)

结束功能


希望这有帮助

Jay


" Matt" <先生******** @ hormel.com>在消息中写道

news:94 ********************************** @ microsof t.com ...我试图在一个
Button_Click事件中调用一个递归子例程。我怎么能这样做?

我试图创建一个单独的Function()但它不会允许我使用我在
Button_Click事件中创建的任何变量。 br />
任何想法?

谢谢!



" Matt" <先生******** @ hormel.com>写道...

我试图在
Button_Click事件中调用递归子例程。我怎么能这样做?

我试图创建一个单独的Function()但它不会允许我使用我在
Button_Click事件中创建的任何变量。 / blockquote>


马特:一个字值得一张图片的1/1000 :-)你能发一个例子吗?

它应该让它更容易想出一个解决方案。


Tom


I am trying to call a recursive subroutine within a
Button_Click event. How can I do this?

I tried to create a seperate Function() but it will not
allow me to use any variables that I created in the
Button_Click event.

Any ideas?

Thanks!

解决方案

In article <94**********************************@microsoft.co m>,
mr********@hormel.com says...

I am trying to call a recursive subroutine within a
Button_Click event. How can I do this?

I tried to create a seperate Function() but it will not
allow me to use any variables that I created in the
Button_Click event.



Can you pass the variables to the recursive function? The GOSUB command
was not implemented in VB.NET so you can''t use that. If there''s too
many variables to pass, you could try placing them in a structure.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele


Matt,
Is this a homework assignment?

I tried to create a seperate Function() but it will not
allow me to use any variables that I created in the
Button_Click event. You would pass "Variables" to the function as parameters, just like any
other function or sub. Alternatively you can declare the "variables" within
the Class itself.

Have you tried something like:

Private Sub Button_Click(...)
Dim x As Integer = 1000
Dim y As String
MyFunction(x, y)
End Sub

Private Function MyFunction(ByVal x As Integer, ByVal y As String)
If x <= 0 Then Exit Function
MyFunction(x - 1, y)
End Function

Hope this helps
Jay

"Matt" <mr********@hormel.com> wrote in message
news:94**********************************@microsof t.com... I am trying to call a recursive subroutine within a
Button_Click event. How can I do this?

I tried to create a seperate Function() but it will not
allow me to use any variables that I created in the
Button_Click event.

Any ideas?

Thanks!



"Matt" <mr********@hormel.com> wrote...

I am trying to call a recursive subroutine within a
Button_Click event. How can I do this?

I tried to create a seperate Function() but it will not
allow me to use any variables that I created in the
Button_Click event.



Matt: A word is worth 1/1000th of a picture :-) Could you post an example?
It should make it easier to come up with a solution.

Tom


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

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