我想创建一个过程,它的参数也是一个过程.可能吗?
我创建了一些程序用作以下参数:
我创建了一些程序用作以下参数:
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")
我相信以下代码是您需要的一个例子.
原文链接:https://www.f2er.com/vb/255163.htmlPublic 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找到
希望这可以帮助.