Calculation - Forum

Forum Navigation
You need to log in to create posts and topics.

Calculation

how can i make an application that's calculate the value of function like this:

#two input for user

1- for value like x=3

2- for function like f(x)=x^3-2

#output button for  calculating the value of function:

ans=25

asmat has reacted to this post.
asmat

@asmat:

I am not sure what you are looking for; when you say ...

#two input for user
1- for value like x=3
2- for function like f(x)=x^3-2

... are you saying that the user would enter BOTH the value for variable x AND the equation (x^3 - 2) ? ... if so, it would be difficult to parse any/all equations the user would enter.

However, if you are looking to provide answer to the hard coded equation for value entered for x by a user, take a look here ... https://webhelp.visualneo.com/Mathematical.html ... at the Math command ... place something like this in the click action event code of the Button ...

Math "([x]^3 - 2)" [result]

1) Replace [x] with the variable associated with your Numeric Input (https://webhelp.visualneo.com/NumericInput.html)

2) You can then display the answer ...

a) either via an AlertBox command

b) or as the content of a Container

asmat has reacted to this post.
asmat

I want to use variable into textInput ..example

I created a sample app with these objects:

1-TextInput with the  variable of  [x]

2- TextInput with variable of  [y]

3-Button with code of :   Math "[y]" 0 [r]

4-TextInput for result [r]

after run the application,  I enter at variable [x] number like 2 and into  [y] variable  function like=  [x]+3

now, I expect the value of the result should be 5 but the result is nothing.

how I solve this problem? is it possible or no?

@asmat:

1-TextInput with the variable of [x]

If you are working with numbers, best to use Numeric Input (not Text Input).

2- TextInput with variable of [y]
3-Button with code of : Math "[y]" 0 [r]

This will NOT work ...

a) when you enter [x]+3 in the second Text Input, it will contain a TEXT (i.e. string) value of "[x]+3"

b) When you ask to do the Math command, the numeric value of [y] is zero (because TEXT does NOT have a numeric value; same as John Smith does not have a numeric value).

4-TextInput for result [r]

Again, if you want to display something, best to use a Container ... Text Input allows user to change the value.

I expect the value of the result should be 5 but the result is nothing.
how I solve this problem? is it possible or no?

1) if you are trying to build some kind of generic equation calculator ... meaning that the user can enter any/every kind of equation ... then the answer is NO !!!

2) But if you are trying to build a calculator for a specific equation (or equations), you can ...

a) Setup one Numeric Input for every variable in your specific equation e.g. if the equation is x+y+3, you should set up one Numeric Input for x and another for y

b) Setup one Button to calculate each equation ... e.g. one to calculate x+y+3 and say another for x^2 + (y/2)

c) In the Click event section for the 1st Button, set up the command ...

Math "[x]+[y]+3" 0 [r1]

& in the Click event section for the 1st Button, set up the command ...

Math "[x]^2 + ([y]/2)" 1 [r2]

... and then use AlertBox or a Container to display [r1] and [r2]

asmat has reacted to this post.
asmat

I was meaning a generic equation calculator.

once I created this kind of application  with neobook two years ago ... at that time i used  parse string function....

but now  with this, I couldn't....

thank you so much for your help

 

@asmat:

 

once I created this kind of application  with neobook two years ago ... at that time i used  parse string function....

but now  with this, I couldn't....

Although you could do some things in NeoBook that you can't do with Javascript (Browsers forbid it because of security concerns), it might still be possible to build a limited-generic facility (with lots of code). VisualNEO Web also has a StrParse command.

If you have details of the kind of operators ... e.g. +-*/^() ... that were supported, and the NeoBook commands used to build such a facility, it might be possible to replicate it on this platform.

 

 

asmat has reacted to this post.
asmat

after run the application, I enter at variable [x] number like 2 and into [y] variable function like= [x]+3
now, I expect the value of the result should be 5 but the result is nothing.

You can not use variable names at run time.
But you can do something like this:

  1. Use "x" instead of "[x]" to write your function.
  2. On the "Calculate" button add this code:
StrReplace "[y]" "x" "[x]" [z] ""
Math "[z]" 0 [result]

This will replace "x" for the value stored in [x] before performing the calculation.
You can use text fields with no problem as the Math command will convert them to numbers.

Take a look at the attached app.

Uploaded files:
  • You need to login to have access to uploads.

Thank you so much...

this is the best way..... and the best answer ... that's i wanted.