Eval Function in VB.NET 
Author Message
 Eval Function in VB.NET

I am building a mapping utility that reads data from an excel file and
completes a set of processes.
Since columns in the excel sheet may vay in positions, my mapping tool
allows me to identify the column.

Sometimes the data i require comes in from two columns. Therefore while
mapping I can specify A+B
Like NetSalary + Tax = Gross.

Is there any object or function that allows me to evaluate a string
expression?

Thanks,
Nasim



Tue, 19 Apr 2005 17:24:34 GMT  
 Eval Function in VB.NET
There seems one way to do this using the MSScriptControl.ScriptControl (COM
Interop)

Dim sc As New MSScriptControl.ScriptControl()
sc.Language = "VBScript"
Dim espr As String = "12 + 3 * 10"
Dim res As Double = sc.Eval(expr)

' display the result
Console.WriteLine("{0} = {1}", expr, res

Nasim



Tue, 19 Apr 2005 19:18:31 GMT  
 Eval Function in VB.NET


Quote:
> I am building a mapping utility that reads data from an excel file and
> completes a set of processes.
> Since columns in the excel sheet may vay in positions, my mapping tool
> allows me to identify the column.

> Sometimes the data i require comes in from two columns. Therefore while
> mapping I can specify A+B
> Like NetSalary + Tax = Gross.

> Is there any object or function that allows me to evaluate a string
> expression?

> Thanks,
> Nasim

Nasim,

You might try something like this...

You could build a dll using jscript and then reference it from your project.
It would look something like:

// JScript source code
class EvalClass
{
    function Evaluate(expression)
    {
        return eval(expression);
    }

Quote:
}

you will have to build this from the command line:

jsc /target:library evaluator.js

Then you can reference the resulting evaluator.dll and Microsoft.JScript.dll
in your VB project.  You could then call the function like this:

Dim ec As New EvalClass()
Dim expr As String = "12 + 3 * 10"
Dim res As Double = CType(ec.Evaluate(expr), Double)

Console.WriteLine("{0} = {1}", expr, res)

This way you don't have to use COM interop... You can stay right in the .net
world :)

HTH,
Tom Shelton



Sat, 23 Apr 2005 15:02:04 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Eval function in VB .Net and C#

2. EVAL function in VB.NET - where is it?

3. Eval Function in VB.NET

4. Does VB.NET has Eval Function?

5. Eval() in VB.NET ??

6. JScript.Eval in VB.NET

7. Eval / Execute in vb.NET

8. execute a variable as a function/sub procedure (like eval function in java(script))

9. eval function? how to call dynamic function name

10. Looking for a VB function like Eval() in ASP or Interpret in REXX

11. Wish List Vote: Eval Function for VB

12. Is there an Eval function in VB?

 

 
Powered by phpBB® Forum Software