Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EVAL() in .NET?

Status
Not open for further replies.

UGrad

Programmer
Oct 15, 2002
40
CA
Hi,
I did some research on this, but I couldn't find any answer.

In classic ASP, I can use eval() to evaluate a string.
For example, if I do eval(len("test")>5), it will return false. Or if I do eval(len("test") > 1 and len("test") < 5), it will return true.

Is there a function in .Net equivalent to eval()??

Please help.
 
Eval really doesn't have a place in a compiled language. Besides, you don't need it to do what you showed in your post.

If eval(len("test")>5)

is the same as

if len("test")>5




if eval(len("test") > 1 and len("test") < 5)

is the same as

if (len("test") > 1 and len("test") < 5)


There is no need for the eval()



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
The reason I asked is because I want to use eval() to evaluate a string. This string is an input from user.

Basically, I have a text box for user to type in a string. Then I evaluate the text in the box.

For example, user can type in:
datediff("d", now, "1/1/2006")

or

5*2-9+10/44 > 10

or

year(now) > 2006 and month(now) < 6


 
Check out this link:

Dynamic Code Execution

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
I found the solution.


Set a reference in your app to "Microsoft Script Control 1.0" It is under the COM tab in references. Then the code is really simple.


Dim SC As New MSScriptControl.ScriptControl
SC.Language = "VBSCRIPT"
Label1.text = Convert.ToString(SC.Eval(TextBox1.Text))

TextBox1.text can be:
datediff("d", now, "1/1/2006") > 1
or
5*2-9+10/44 > 10
or
year(now) > 2006 and month(now) < 6



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top