Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
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.
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 22-Jan-13 0:11am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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!)
DDR 4 at 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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

For this purpose we can use

& the link for the same is:-

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

  Print Answers RSS
0 OriginalGriff 390
1 Maciej Los 205
2 Peter Leow 140
3 Suvendu Shekhar Giri 134
4 Abhinav S 126
0 Sergey Alexandrovich Kryukov 9,623
1 OriginalGriff 8,895
2 Peter Leow 5,044
3 Kornfeld Eliyahu Peter 3,333
4 Maciej Los 2,561

Advertise | Privacy | Mobile
Web01 | 2.8.150327.1 | Last Updated 29 Aug 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100