加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

vb.net – 如何将MethodName作为VBNET中的过程参数传递

发布时间:2020-12-17 00:27:20 所属栏目:大数据 来源:网络整理
导读:我想创建一个过程,它的参数也是一个过程.可能吗? 我创建了一些程序用作以下参数: Private Sub Jump(xStr as string) Msgbox xStr " is jumping."End SubPrivate Sub Run(xStr as string) Msgbox xStr " is jumping."End Sub 这个程序应该调用以上程序: Pr
我想创建一个过程,它的参数也是一个过程.可能吗?
我创建了一些程序用作以下参数:
Private Sub Jump(xStr as string)
    Msgbox xStr & " is jumping."
End Sub

Private Sub Run(xStr as string)
    Msgbox xStr & " is jumping."
End Sub

这个程序应该调用以上程序:

Private Sub ExecuteProcedure(?,StringParameter) '- i do not know what to put in there
     ? ' - name of the procedure with parameter
End Sub

用法:

ExecuteProcedure(Jump,"StringName")
 ExecuteProcedure(Run,"StringName")
我相信以下代码是您需要的一个例子.
Public Delegate Sub TestDelegate(ByVal result As TestResult)

Private Sub RunTest(ByVal testFunction As TestDelegate)

     Dim result As New TestResult
     result.startTime = DateTime.Now
     testFunction(result)
     result.endTime = DateTime.Now

End Sub

Private Sub MenuItemStartTests_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MenuItemStartTests.Click

     Debug.WriteLine("Starting Tests...")
     Debug.WriteLine("")
     '==================================
     ' Add Calls to Test Modules Here

     RunTest(AddressOf Test1)
     RunTest(AddressOf Test2)

     '==================================

     Debug.WriteLine("")
     Debug.WriteLine("Tests Completed")

End Sub

整个文章可以在http://dotnetref.blogspot.com/2007/07/passing-function-by-reference-in-vbnet.html找到

希望这可以帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读