• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 89
  • Last Modified:

how to pass a function name as a argument into another one function ?

how to pass a function name as a argument  into another one function and  how to run this passed function name into passed function.
for example :
public class first
public sub test
msgbox "hellow"
end sub
end class

public class  second
public sub well
dim t as new first
GetAndRunMethod(addressOf t.test())
end sub
public sub GetAndRunMethod(dim GetFun)
call GetFun
end sub
end class

how to achieve my above purpose ?
0
tamilsoft
Asked:
tamilsoft
1 Solution
 
CodeCruiserCommented:
Examples here

http://dotnetref.blogspot.com/2007/07/passing-function-by-reference-in-vbnet.html

stackoverflow.com/questions/2734166/vb-net-function-that-takes-other-functions-as-a-parameter-and-executes-them
0
 
nepaluzCommented:
you already have it, initialize the class and reference the sub you need to call,in your case:
t.test()

Open in new window

will run the sub in the first class
0
 
käµfm³d 👽Commented:
Instead  of "Dim GetFun", try "ByVal GetFun As Action". This is essentially what CodeCruiser's first link discusses. The difference is:  use Func when you have a Function you want to pass; use Action when you have a Sub you want to pass.

Also, remove the parentheses when you pass the function.

i.e.

GetAndRunMethod(addressOf t.test)

Open in new window

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
tamilsoftAuthor Commented:

according  experts "codecruiser" reply, following statements are not accepted

Public Sub passFun(ByVal a As Func(Of T))

End Sub

how to use it ?
0
 
käµfm³d 👽Commented:
Because your "Sub Test" does not return a value, you need to use an Action, not a Func. In other words:

Public Sub passFun(ByVal a As Action)

End Sub

Open in new window

0
 
tamilsoftAuthor Commented:
ok.  kaufmed.
"public sub passfun" works perfectly.

public function add(a as integer, b as integer) as integer
return a+b ;
end sub

how to pass and return  Add(2,3) into function ?
0
 
käµfm³d 👽Commented:
I answered this in https:#a37291017
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now