Execute a formula

Is there any way to execute a formula in XOJO like the following:

Two fields which contain variables.

Numerator (Example - nCurrentAssets + nOtherAssets)
Denominator (Example - nCurrentLiabilities + nOtherLiabilities)

Formula = Numerator / Denominator

I want to store the variable amounts required to perform the calculation in the numerator and denominator field and then just execute the formula ( result = numerator / denominator )

You can do something like that via XojoScript. Your code will literally write the script, execute it, then use the result.

Just make sure the stuff you are executing won’t do something malicious.

Thanks for the reply Kem. I kind of thought I might be able to do it in XOJOscript but wasn’t sure. You don’t know of any examples that I might find showing how to use XOJOscript, do you?

Check out the “Evaluator” example project in ‘Advanced:XojoScript’.


Thank you Jim.

if you don’t want to use XojoScript… google “SHUNTING YARD ALGORITHM”

I use this in all my translator/compiler oriented projects

If the formula is always the same, i.e.:
result=(Example - nCurrentAssets + nOtherAssets)/(Example - nCurrentLiabilities + nOtherLiabilities)
then there is hardly any reason to build an expression evaluator.


The formula changes for a number of items.

Dave - That looks like it would certainly work, but Xojoscript looks much simpler and should work nicely.

you could download mathfield


I’ve not used it, but i had a play with it a few years back