InputBox and Button to change a graph

Nick Chura shared this question 5 years ago
Answered

1. Can you explain what I've done wrong in the following?

2. Can you provide a better solution for my issue?


I want a user to be able to type an expression into an InputBox, and then click a Button in order to make a graph. I don't want the InputBox linked to the graph (or something on which the graph depends), but I want the button to control the change.


I tried making a free graph h(x) = -5 (so it is off screen). In the Button's OnClick script, I wrote: SetValue[h, %0]

This returns an error when the button is clicked, whether I've typed a number or an expression into the InputBox.


I'm not sure how I've misused the value of %0 here.


[I then tried a variation where I create a free object val = -5, make h(x) = val, and then use the button to change the value of val. This also doesn't work. Clearly I'm misusing %0 or SetValue in some way.]


Thank you all for your help!

Comments (6)

photo
1

firstly, %0 should in script of "on click inputbox", not in "on click button".

secondly, use a "middleman" var, like

  1. SetValue[a, %0]

third: in "on click button" script:

SetValue[b,a]

and the b is used by graph, like h(x) = b x^2.

please see attachment:

photo
1

Thanks, Tang -


Unfortunately, your method only seems to allow me to type a numerical input, not a variable. I want to be able to type a function of x into the input box.


Also, why did my method not work? What exactly is "%0"? How have I misused it as a variable?


Thanks.

photo
1

1. first define a "middleman" function, say, (and do not show it)

  1. f=x+2


2. create input box , this input box "linked object to" that function (like the post of Juan Carlos below), or another way, in its click scripting,

  1. SetValue[f,%0]

3. create a function, say

  1. g=x+6

4. cratea a button, in its click scripting:

  1. SetValue[g,f]


when you have error, maybe geogebra does not work, the better way is to close the software and make a new spreadsheet.

good lucky!

Files: 2.ggb
photo
photo
1

Hello,


Is this what you need? See the attached file.


Saludos.

photo
1

Yes -- that is what I needed.


Thank you, Juan Carlos!

photo
photo
1

Hi,


Here is another option: https://ggbm.at/BcYJgmEk


Saludos.

© 2023 International GeoGebra Institute