0

im trying to create something something similar to this, parsing string to equation with vb now, my problem is is the exponents, can anyone help me with this, or is there any easier way to convert that string to a mathematical equation?

func = (function).Text 'ex: x^4-x^3+x-5
tol = TextBox2.Text           <- you can ignore this one
mloop = TextBox3.Text         <- you can ignore this one
a = rangeA.Text
b = rangeB.Text
funcA = Replace(func, "x", a)
funcB = Replace(func, "x", b)

my main problem really, converting that string to an immediate usable mathematical equation. thanks!

Community
  • 1
  • 1
user2124478
  • 27
  • 1
  • 6
  • The answer you linked to has a case statement. Just add the "^" case. – djv Jul 29 '14 at 18:45
  • how about the precedence of the operators? – user2124478 Jul 29 '14 at 19:11
  • So you would also want to add a "(...)" case. – djv Jul 29 '14 at 19:15
  • the input is validated, only accepting numbers,x, and the operators +,-,^ since it wont be multiplying nor dividng, so it doesnt really have the "(..)",also saw something like that coded in java, but im gonna try it out, post later for updates, thanks btw! – user2124478 Jul 29 '14 at 19:25
  • 1
    Make an initial loop to parse "^", then go back and parse the rest. – djv Jul 29 '14 at 19:29
  • ok, so the problem with the solution in the link i provided is -its only limited to 2 terms – user2124478 Jul 30 '14 at 12:25
  • And single digits, I'd like to help but I'm sure there's an existing algorithm somewhere that does this and I don't want to reinvent the wheel. – djv Jul 30 '14 at 15:24
  • 1
    Search `vb.net expression evaluator`, 1st result: http://www.codeproject.com/Articles/9519/An-expression-evaluator-written-in-VB-NET – djv Jul 30 '14 at 15:25
  • ok, really cant find anything, or im just thick and cant absorb anything i find, i think i should just go with what i was trying to make before, im just gonna convert the string to an array, and use a loop for the operators and use case, since i also need to multiply X by n in nX ill also be using ifs. thanks by the way guys, gonna post my solution afterwards. – user2124478 Jul 31 '14 at 17:52

0 Answers0