|
-
Nov 15th, 2010, 03:17 AM
#1
Thread Starter
New Member
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
-
Nov 15th, 2010, 03:43 AM
#2
Re: From string to maths command
Read this. Turn on java for examples.
http://www.chris-j.co.uk/parsing.php
-
Nov 15th, 2010, 03:48 AM
#3
Thread Starter
New Member
Re: From string to maths command
 Originally Posted by cicatrix
Thank but....I understand what I need to do but don't know how to do it :S
-
Nov 15th, 2010, 03:51 AM
#4
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.
-
Nov 15th, 2010, 03:57 AM
#5
Thread Starter
New Member
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
-
Nov 15th, 2010, 04:03 AM
#6
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?
-
Nov 15th, 2010, 04:16 AM
#7
Thread Starter
New Member
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.
-
Nov 15th, 2010, 05:20 AM
#8
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.
-
Nov 15th, 2010, 08:01 AM
#9
Re: From string to maths command
 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
-
Nov 15th, 2010, 08:53 AM
#10
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. )))
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|