Is there a way to convert string into a mathematical notation?

like in topic, is there any way to convert string into a mathematical notation?

For instance I have a string like “4 + 84 / 8” and I want Xojo to calculate that in mathematical order.

Is there any function, plugin etc. that would help me?

Which platform? On Mac and Linux, you can use the Shell and call “bc”.

On any platform, you can use XojoScript with a script like:

var x as double = <+formula+>
print x.ToString

You would replace “<+formula+>” with your actual formula, then capture the output from the XojoScript.

Or you could write your own parser.

Hi Dominik,

welcome to the forum. Interesting question !

On windows. How can I do that with XojoScript? I’m new to all the plugins and scripts and I don’t know how to use/make that :confused:

Start here:

https://documentation.xojo.com/api/code_execution/xojoscript.html

This is kind of an advanced task, so I’ll give you the general steps here. Please post your questions as you encounter them and we’ll try to help out.

  1. Create a new class, Calculator, that is a subclass of XojoScript.
  2. Add a public property, Result As Double.
  3. Implement the Print event so it stores the message in Result as a double.
  4. Add a function called Calculate( formula As String ) As Double.
  5. In that method, set the Source to the script above with the formula inserted in the right place.
  6. Call Run, then return the value in Result.

File>New Project>Examples>Advanced>XojoScript>Evaluator

1 Like

Thank you so much!

Thanks for help to you too, I will give a try to understand these xojoscripts :wink:

Well sure, if you want to take the easy way…

(I forgot that was there.)

1 Like