Execute a formula

  1. 9 months ago

    John F

    1 Aug 2016 Pre-Release Testers, Xojo Pro Omaha, Nebraska

    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 )

  2. Kem T

    1 Aug 2016 Pre-Release Testers, Xojo Pro New York

    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.

  3. John F

    1 Aug 2016 Pre-Release Testers, Xojo Pro Omaha, Nebraska

    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?

  4. Jim S

    1 Aug 2016 Central Florida

    Check out the "Evaluator" example project in 'Advanced:XojoScript'.

    Jim

  5. John F

    1 Aug 2016 Pre-Release Testers, Xojo Pro Omaha, Nebraska

    Thank you Jim.

  6. Dave S

    1 Aug 2016 San Diego, California USA

    if you don't want to use XojoScript... google "SHUNTING YARD ALGORITHM"

    I use this in all my translator/compiler oriented projects

  7. 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.

  8. John F

    2 Aug 2016 Pre-Release Testers, Xojo Pro Omaha, Nebraska

    Robert

    The formula changes for a number of items.

  9. John F

    2 Aug 2016 Pre-Release Testers, Xojo Pro Omaha, Nebraska

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

  10. Russ L

    2 Aug 2016 Pre-Release Testers, Xojo Pro

    you could download mathfield

    http://www.benandruby.com/bens_software/

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

or Sign Up to reply!