35 views
in Platform Packages by

The eval() function evaluates the string expression and returns its value

For example, eval("10 + 1 - 2") returns 9.

1 Answer

0 votes
by

Hello,

this sounds like you want to implement some kind of calculator based on a string input.

In general, there are two aspects: parsing the string and doing the math. In order to give you some helpful hints (instead of implementing that for you), it would be helpful to know, what you have done so far and what is missing.

Maybe the following links help you:

Data type string and the different instant methods

Operators

I hope this helps.

Best regards,

Manfred.

by
Hello,

Yes I want to make a calculator. So far I have the UI and I was thinking how to implement the functionality. In Java I have used the eval() built in function and I was wondering if there is something like that in Chora

But any other idea how to implement the calculator would be welcome.

Thanks☺️
by

Hello,

if you want to make a calculator, why do you want to work with strings? The calculator itself is more or less (depending on the feature set) straight forward - but the usage of strings makes it more inconvenient.

Let's assume you have a GUI application with a couple of buttons for numbers ('0'...'9') and some buttons for operators ('+', '-', '/', '*', ...). In the buttons OnActivate handler you process the inputs:

  • If a number button is pressed, the current value is multiplied by 10 and the new digit is added (= the current input value).
  • When an operator key is pressed, the current input value is stored in an intermediate variable and the operator is also stored to calculate the next input value against the previously stored value.
  • ....


Does that help? Of course, the above is just a rough sketch and not a complete calculator...

Best regards,

Manfred.

by
Thank you!

Regards,

Amy

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...