A function to build and call a function

Varcy Hilten

New member
Joined
Aug 4, 2005
Messages
4
Programming Experience
5-10
Does anyone have an idea how to begin on this. I want to programmatically build a function and then call it during run time. Is it possible?
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
making functions is easy simply start in the code window of a form/module and start with

Private Function FunctionName (Byval Input As DataType) As DataType
Return SomeValue
End Function

like:
Private Function PlusOne (Byval Number As Integer) As Integer
Return Number += 1
End Function

then you simply call the function by name:

Dim intMyNumber as Integer = 3
intMyNumber = PlusOne(intMyNumber)

with that intMyNumber started at 3 and now equals 4
 

TechGnome

Well-known member
Joined
May 23, 2005
Messages
896
Programming Experience
10+
Juggalo - did you miss this part: " ...programmatically build a function ..."

I assume he means to creathe function by concatenating a string to gether, then executing it some how....

This is possible in .NET.... how ever, it involves running the compiler in memory, then using reflection to get to the code in memory. Ick! All examples I've seen have been no less than 20 lines or so jsut for a simpl 1+1 function. I've been confused by is all.... If I find the article again, I'll post it's linke... I think it was on DevX somewhere...

Tg
 

Varcy Hilten

New member
Joined
Aug 4, 2005
Messages
4
Programming Experience
5-10
That's correct Tg. Concat strings then somehow compile in mem. I think the codedom functionality may have to be used. I'd love to see an example if you come across one.

Thanks for the response Juggalo. I could have been more clear in my question.
 

TechGnome

Well-known member
Joined
May 23, 2005
Messages
896
Programming Experience
10+

ayozzhero

Well-known member
Joined
Apr 6, 2005
Messages
186
Location
Malaysia
Programming Experience
1-3
That's the thing... lengthy codes and we have to build it (almost) like building a class. If only there is a thing as simple as 'EVAL' in Java...
 

bloukewer

Well-known member
Joined
Jul 2, 2004
Messages
88
Programming Experience
3-5
While we are on the topic of weird functions... is there a way by which functions can be called through parameters? I know that when you start a new thread you need to pass a function as a constructor parameter. My question is: How do I do this with my own sub's or functions. (How do I create addressof parameters?)
 
Top Bottom