Results 1 to 10 of 10

Thread: From string to maths command

  1. #1

    Thread Starter
    New Member headbuster's Avatar
    Join Date
    Nov 2010
    Posts
    10

    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

  2. #2

  3. #3

    Thread Starter
    New Member headbuster's Avatar
    Join Date
    Nov 2010
    Posts
    10

    Re: From string to maths command

    Quote Originally Posted by cicatrix View Post
    Read this. Turn on java for examples.
    http://www.chris-j.co.uk/parsing.php
    Thank but....I understand what I need to do but don't know how to do it :S

  4. #4
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    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.

  5. #5

    Thread Starter
    New Member headbuster's Avatar
    Join Date
    Nov 2010
    Posts
    10

    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

  6. #6
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    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?

  7. #7

    Thread Starter
    New Member headbuster's Avatar
    Join Date
    Nov 2010
    Posts
    10

    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.

  8. #8
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    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.

  9. #9
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: From string to maths command

    Quote Originally Posted by cicatrix View Post
    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
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  10. #10
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    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
  •  



Click Here to Expand Forum to Full Width