Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,

I want to execute mathematical expressions from file at runtime using .net FW 4.0, If any body can share the code, It will be very helpful.

Requirement:-
I have stored a function in a text file:-

Function add(ByVal a As Int16, ByVal b As Int16) As Int32
Return (a + b)
End Function

& i have to pass the value of a &b and 've to get the return value(i.e. a+b) in my main program.
__________________________
Thanks in advance
Posted

If all you want to do is evaluate mathematical operations, then executing VB code is overkill. Have a look at this:
Math Parser .NET C#[^] You feed ita string, it returns the result.

While you can compile and execute VB code from within a program, it is a lot more complex to do, and a lot more dangerous (since it will have access to all the .NET methods, which is probably not what you want at all!)
 
Share this answer
 
Comments
DDR-4 22-Jan-13 5:49am    
Thanks a lot "OriginalGriff" :)
Your solution & suggestions are really nice & helpful, But in my requirement there will be equations like(Sorry i didn't mention) :-

a = add(5, 10) + subt(80, 40) ' Stored in text file

Where add() & subt() are(/has to be) defined in main program.
For this purpose we can use
Quote:
CodeDOM

& the link for the same is:-

Quote:
CodeDOM
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900