Click here to Skip to main content
12,299,086 members (51,474 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB 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.

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 21-Jan-13 23:11pm
DDR-4616
Rate this: bad
 
good
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!)
  Permalink  
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

For this purpose we can use
Quote:
CodeDOM

& the link for the same is:-

Quote:
CodeDOM
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 29 Aug 2013
Copyright © CodeProject, 1999-2016
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