zoggolino Posted June 2, 2006 Posted June 2, 2006 I'm programming a science tool. for this i have an input string like this: "y= 1.3*exp(-x*3)" from an input textbox. Now I have to convert this string into the form: dim py as integer dim px as integer py = 1.3*math.exp(px*3), becaus i have to calculate the formula. how can i do this. is there a possibilty to include a code fragment in a string into a vb project? thanks a lot for any help. Quote
Arch4ngel Posted June 2, 2006 Posted June 2, 2006 If you want to go through that way, you'll have to build the code to generate the code. After, you might look there: http://www.codeproject.com/vb/net/DotNetCompilerArticle.asp This will help you set things up. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Arch4ngel Posted June 2, 2006 Posted June 2, 2006 Unless you do your own string analysis and parse/calculate everything... no. Unless you can find a Third-Party component. The one I saw was there: http://www.c-sharpcorner.com/UploadFile/mgold/CodeDomCalculator08082005003253AM/CodeDomCalculator.aspx it was looking good. Tell me what you think Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Leaders snarfblam Posted June 2, 2006 Leaders Posted June 2, 2006 I've written VB7 code that could evaluate an arithmatic expression with trigonometric and exponential functions in the past. If you sit down and really think about it, it isn't all that difficult to code. Precedence can be implemented by layered functions. PerformAddition calls PerformMultiply, which calls ParseValue which parses a constant and returns it to PerformMultiply, which continues calling ParseValue and examining operators, applying the multiplication and division operators until it reaches an operator not at its level of precedence, and returns to PerformAddition, which continues to call PerformMultiply and add the evaluated terms until it finds an operator above its level of precedence. Perentheses equals recursion. (That's a little simplified but you get the idea.) When performance became an issue I wrote a program to extract the constants and store the expression in a tokenized format with the order of operations applied as the expression is tokenized so that what was left was a very simple sort of stack-based bytecode which could be interpreted very quickly. Of course, if you have a ready-made solution or would prefer to use reflection-emit or codedom any of those solutions would certainly work. Quote [sIGPIC]e[/sIGPIC]
zoggolino Posted June 6, 2006 Author Posted June 6, 2006 I implemented the on-the-fly compiler from code zone. it works properly and was easy to apply. thanks a lot Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.