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?
 
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
 
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
 
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.
 
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...
 
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?)
 
Back
Top