Strange behavior of the program when synchronizing the values of the textbox and the slider

But I requested the text from this object. Can't it be written to a variable? Or is there a problem with the types of values? By the way, how does Ap Inventor convert variable types? There is only a number type conversion in blocks. How is text converted to a number, and vice versa?

AI2 uses Duck Typing. (If it looks like a duck, walks like a duck,... it is a duck).
It will attempt to convert between text and number types as needed, as long as the text is non-blank.

There are a bunch of test blocks like is_number to help guard against conversion fails.
Typeblock 'is ' to see them all.
Duck Typing does not extend to text representations of lists or dictionaries.

And then how is an empty string interpreted when entering data into a mathematical expression?

You will usually get an error if you do not set a default value e.g. "0"

But then how to ignore the input if the user left an empty field in the TextBox and pressed Enter?

Use the following pseudo code

If not isEmpty Textbox.Text
then do the calculation

Taifun

The user can erase the digit and press Enter.

It seems to have done everything correctly, but the figure in the TextBox is not displayed, and it does not react to the movement of the slider. What is the error?
Change_variable2.aia (61.6 KB)

Maybe something like this:

Did as you suggested, added Slider extension, added commands. Really didn't figure out why they are? I started the emulator - the text is still not visible, but now when you press Enter, the slider always shifts to the right.
P.S. I inserted the "round" blocks later, but it didn't change anything.
P.P.S. the problem with the visibility of numbers in the TextBox was solved by setting the height of the box to automatic. Now I see that the movements of the slider are displayed in the TextBox, but changing the text does not synchronize the position of the slider.


Change_variable3.aia (72.5 KB)

Observing the work of my first option, I discovered a pattern - when the first two-digit number is set in the TextBox, the second digit turns into one. With a secondary set of the same number, it is stored correctly! When typing a three-digit number with a non-zero third digit, this digit is also reset to one. If the third digit is 0, then at the first set, the second digit decreases by a dozen. But in any case, when the same number is repeated, the set is saved correctly!

Added the Taifun Textbox extension function to its original version. When you change the text in the Screen 2 line and press Enter, nothing changes. They don't seem to be working properly either.
Change_variable (1).aia (63.4 KB)

Have you read Taifun's examples of using this extension?

1 Like

I added the TextBox content tracking initiation from Taifun Textbox to Screen2. Nothing has changed.
Change_variable (2).aia (63.1 KB)

Try this one:
Change_variable_4.aia (63.2 KB)

This is like a snake biting its own tail. The Textbox changes to the Slider and the Slider changes to the Textbox, a stack overflow occurs.
To avoid this, use the Slider extension.

Change_variable_3.aia (29.0 KB)

When I replace the text, clearing the previous one to an empty TextBox before entering a new number, the same error pops up. In addition, for some reason, the wrong number is displayed in the window, which I enter on the keyboard!
When replacing the control unit with a reaction when entering text in the TextBox, it is saved correctly, but it is not synchronized with the slider.

Try

Change_variable_4.aia (29.1 KB)

1 Like

Bingo, now it works! Juan_Antonio, thank you so much!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.