Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
If your expression is always of th form A+B-C then you can simplify things. But if you want to evaluate any random equation you're looking at a lot of work. You'ld have to generate a parser that will scan the line of text and identify numeric values and operators. You'll then need to perform the indicated operations.
In the old days of BASIC you could place that formula on a numerical input statement and the BASIC itself would parse it out. However it could be corrupted by entering invalid characters, etc.
The relative complexity comes when you start taking all the permutions into account. Are the only functions you need + & -? Or do you need * and / as well? How about trig functions, Sin(), Cos(), Tan()? Powers? Are your numbers only going to be integers? or do you need to handle reals? How about fractions? Are you going to allow $ signs and ,'s? This can get really messy in a hurry.
Search the PAQ's, I've seen code for this posted before.
M