From string to maths command
Hello
I am trying to make a calculator (how original) but I am also trying to make it like a console.
I have a textbox in which you enter a command and a list in which the lines appear.
My question is how can I translate the plain text which the user enters i.e 3*(2+4) to a maths command so that VB can display the answer?
Thanks
Re: From string to maths command
Read this. Turn on java for examples.
http://www.chris-j.co.uk/parsing.php
Re: From string to maths command
Quote:
Originally Posted by
cicatrix
Thank but....I understand what I need to do but don't know how to do it :S
Re: From string to maths command
The article explains how. If you need an advice in implementing this in vb.net then you need to be more specific. What exactly you don't know how to do (provided you read and undestood the algorithm).
Step 1: Convert infix notation (2 + 2) to postfix (RPN) ( 2 2 +)
Step 2: Implement Shunting Yard algorithm for evaluation.
Re: From string to maths command
I guess it's to complicated (for me) to do it [I am a beginner]
Maybe I'll use some other methods like http://www.vbforums.com/showthread.php?t=624262
Thanks
Re: From string to maths command
It uses the same algorithms. And there's nothing all that difficult. Are you going to copy-paste the code you've found or are you going to make a calculator?
Re: From string to maths command
I am trying to learn how to make one
I started learning VB 3 days ago...
Now I am trying to figure out the code from .paul.'s calculator so that I can understand how it works (because it actually worked when I combined it with my code)
And also my main goal is not to make a calculator for simple problems like 179/5+(30*4). I will make it solve quadratic equations and so on.
Re: From string to maths command
You've got a good way to go then. But without undestanding more basic concepts your progress will be slow. I doubt that you can understand how code works just by looking at it without knowing why there is this line and why there is that. The algorithm comes first then comes the program code. That's why I directed you to the link explaining what exactly needs to be done in order to evaluate an expression. Once you know what to do, the rest would be a simple thing about how to do trivial things.
Re: From string to maths command
Quote:
Originally Posted by
cicatrix
It uses the same algorithms. And there's nothing all that difficult. Are you going to copy-paste the code you've found or are you going to make a calculator?
I have had (am having) several attempts at this. It is more difficult than it looks, OR I am dumber than I know ;)
Re: From string to maths command
It was not as difficult for me as it was time consuming. I think everyone's written a compiler at least once and expression evaluator is the core of it. The difficult part was to write operators for all data types (say you don't want to multiply a string by a double, etc). The whole thing was 1500+ lines of code. )))