VB Equation solver. - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# VB Equation solver.

Posts: 104Member
I've been writing a calculator that shows all the steps in working out a sum. I've currently done showing the working out for "+", "-", "*" and "/". To do that I needed to get a parser to parse an equation (Ie. if I got 5+3+5+6*5+3*5/3" It would work through the sum giving me numbers I could deal with for showing the working out). Having done that, I want to add the ability to solve equations like "5X-2X^2+5-3=7X". In order to do that, I need an idea as to how to make such a parser (Even source code...). I tried one idea - I took out "X" with its Index and its exponent on the side containing "X" and sent the sum whch didn't contain "X" into the parser to return me a number and then "-"ssed "X" from it (Or "+"ssed, depending on the sum) and it returned me the answer. The problem with this was that I only managed to work out code to take out ONE "X" with its exponents.

If you have code, an idea or anything, pls reply.

• Posts: 1,134Member
: I've been writing a calculator that shows all the steps in working out a sum. I've currently done showing the working out for "+", "-", "*" and "/". To do that I needed to get a parser to parse an equation (Ie. if I got 5+3+5+6*5+3*5/3" It would work through the sum giving me numbers I could deal with for showing the working out). Having done that, I want to add the ability to solve equations like "5X-2X^2+5-3=7X". In order to do that, I need an idea as to how to make such a parser (Even source code...). I tried one idea - I took out "X" with its Index and its exponent on the side containing "X" and sent the sum whch didn't contain "X" into the parser to return me a number and then "-"ssed "X" from it (Or "+"ssed, depending on the sum) and it returned me the answer. The problem with this was that I only managed to work out code to take out ONE "X" with its exponents.
:
: If you have code, an idea or anything, pls reply.
:

Look into using regular expressions. The book "Programming Microsoft Visual Basic.NET" By Franscesco Balena has an actual equation parser in the Regular Expressions chapter. It will handle an equation such as ...

2X^2+5-3=7X

Accept maybe the "^" operator which can be easily added. The code is too long to list right now.

• Posts: 104Member
: : I've been writing a calculator that shows all the steps in working out a sum. I've currently done showing the working out for "+", "-", "*" and "/". To do that I needed to get a parser to parse an equation (Ie. if I got 5+3+5+6*5+3*5/3" It would work through the sum giving me numbers I could deal with for showing the working out). Having done that, I want to add the ability to solve equations like "5X-2X^2+5-3=7X". In order to do that, I need an idea as to how to make such a parser (Even source code...). I tried one idea - I took out "X" with its Index and its exponent on the side containing "X" and sent the sum whch didn't contain "X" into the parser to return me a number and then "-"ssed "X" from it (Or "+"ssed, depending on the sum) and it returned me the answer. The problem with this was that I only managed to work out code to take out ONE "X" with its exponents.
: :
: : If you have code, an idea or anything, pls reply.
: :
:
: Look into using regular expressions. The book "Programming Microsoft Visual Basic.NET" By Franscesco Balena has an actual equation parser in the Regular Expressions chapter. It will handle an equation such as ...
:
: 2X^2+5-3=7X
:
: Accept maybe the "^" operator which can be easily added. The code is too long to list right now.
:
:
: