Forum Moderators: open

Message Too Old, No Replies

eval function not working

...in asp.net VB script

         

nbozic

3:00 am on Aug 29, 2004 (gmt 0)

10+ Year Member



Hi,

I'm trying to evaluate string formulas. I tried something like this:
arithmetic = "2 + 4 * 95 - 6"
eqResult = eval(arithmetic)
but it didn't work. I got an error that "eval" is undeclared.
Does asp.net support the evaluation of strings in the first place? I know Javascript and ColdFusion do...

Thanks,

NB

raywood

1:35 pm on Aug 29, 2004 (gmt 0)

10+ Year Member



You usually get this error when you have not imported the namespace containing the class you're trying to use.
Try importing System.Web.UI.DataBinder.

raywood

1:52 pm on Aug 29, 2004 (gmt 0)

10+ Year Member



It doesn't seem like you're trying to do databinding anyway. I think the eval method can only return an object or a string. I don't think the eval method is what you need here. Seems like you need to put the numbers into a collection or array to do arithmetic on them. I'll be waiting to see if someone has a good answer. I'd like to see a simple way to do it also.

nbozic

7:07 pm on Aug 29, 2004 (gmt 0)

10+ Year Member



I was thinking about doing it as you said (using arrays), but I thought that there is an asp.net function that can make it faster and easier (like eval function in regular asp and coldfusion).
I would definitely prefer to use a function like that, if it exists.

RainMaker

1:45 pm on Aug 31, 2004 (gmt 0)

10+ Year Member



this could help

[odetocode.com...]

but I think you was looking for something a little easier than that. I have been using ASP.NET for a while now and I haven't ran into something to the equivalent of eval();

Really, .NET code behind was meant to have the DataTypes that they have now. They were meant to be used accordingly. By the time you convert your elements to Integers....using Convert.ToInt32(string) it would be probably just as fast by the time it decided to do all the parsing for eval(). Plus when you convert them...you KNOW that they are of this DataType and everything is consistant in your code....and very straight forward. Although this is a different concept for some peeps but that is just me. Hope that helps.

nbozic

10:18 pm on Sep 5, 2004 (gmt 0)

10+ Year Member



Thanks! I'll give it a try.