how can i set operators priority in vb.net -



how can i set operators priority in vb.net -

dim equation string dim numbers() string dim operators new list(of string) dim result double dim rx new regex("(\+|\-|\*)+") dim matches matchcollection equation = textbox1.text numbers = equation.split(new string() {"+"c, "-"c, "*"c}, stringsplitoptions.none) matches = rx.matches(equation) dim m1 match each m1 in matches operators.add(m1.value) next result = cint(numbers(0)) dim integer = 1 numbers.getupperbound(0) select case operators(i - 1) case "*" result *= cdec(numbers(i)) case "+" result += cdec(numbers(i)) case "-" result -= cdec(numbers(i)) case " ^" result ^= cdec(numbers(i)) end select next messagebox.show(result)

that's code, illustration "1+4+2*3" how can edit code start multiplication first , partition + , - . have idea?

it seems trying write tokenizer , parser. existing code need alter accomplish this.

see next links, of these have sourcecode can download:

doing math in vb.net eval in javascript

vb.net- evaluating mathematical look in string in-a-string

http://ncalc.codeplex.com/

http://www.codeproject.com/articles/13779/the-expression-evaluator-revisited-eval-function-i

http://www.codeproject.com/articles/274093/math-parser-net

http://www.codeproject.com/articles/220042/easily-create-your-own-parser

http://www.codeproject.com/articles/9519/an-expression-evaluator-written-in-vb-net

vb.net

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -