Evaluate code in vb.net (not for mathematical expressions)

  • Thread starter Thread starter joaotsetsemoita
  • Start date Start date
J

joaotsetsemoita

Hi everyone,

This has been been asked before, however before I came here and post
this I really researched a lot and couldn't find a clear answer for my
problem.

Basicaly I need to run code that is stored in the database. More
detailed:

I have a DB table that contains something like this

id code
1 now.day
2 strName
3 monthname(now.month)

and then I have a string like this: "hello #_name#. Today's day is
#_day# and the month is #_month#."

(strName is a variable in my code, lets supose at the time this
function runs will contain the name Jay)

Then I want to string replace what is inside the hash's with the code
in the database in order to get something like
"hello Jay. Today's day is 28 and the month is May"

However what I get when I do the replace is "Hello strName. Today's
day is now.day and the month is monthname(now.month)."

Ofcourse I could just do a Select Case, but the goal is to later on,
add more records to the table to run diferent things, like other
variables or now.month, etc without having to change the code itself
addind more "cases"

I was told to look at something that is called reflection but it
looked a bit complicated for what I'm trying to achive and I have to
say this is my first big .NET project. I've just done small projects
in asp.net and Im not very familiar with .NET at all.

I hope all this makes sense.

Any sugestions, code examples, links to articles, anything that might
help me is higly appreciate.

Thanks in advance

Joao
 
I was told to look at something that is called reflection but it
looked a bit complicated for what I'm trying to achive and I have to
say this is my first big .NET project. I've just done small projects
in asp.net and Im not very familiar with .NET at all.

I hope all this makes sense.

Any sugestions, code examples, links to articles, anything that
might help me is higly appreciate.


Yes, reflection is one way you can go. What you want to do is create,
compile and execute source code at runtime. This is by far not the
easiest thing you chose. Have a look here:

http://msdn.microsoft.com/en-us/library/650ax5cx.aspx

Be aware that source code has a defined structure. For example, every
executable statement must be in inside a procedure that must be called
from anywhere. The procedure must be part of a class, and so on. So, in
order to create compilable code, at least a skeletal structure must be
created.


Armin
 
Hi Armin,

thanks for your reply. I will look at that link carefuly during today.
Thanks once again.

Joao
 
Back
Top