Text substring function crashes?

I’m kinda stunned that the text substring only works with hard-coded strings. When I use a variable, no joy.

The first Button1 works, the second version crashes! Variable app year displays 2020 in the Alert message.

How useful is a function that has to be hard-coded? Or am I missing something here?

In order not to be surprised, you just need to display the values of all blocks on the screen and see what is in them. For this reason, display the value of the GetYear block on the screen and app year. After this it is necessary to check the length of the text field app year

Check it out and you will understand what the problem is


The text substring does allow for variables, but they have to be text. If we declare app year to be a text var, then setting it to the Date_Input GetYear casts it into a num var. If we declare app year as a num var, then it still needs to be cast into a text var in order for the text substring to work. Am I right?

Neat trick, worked great in my app. Thank-you very much.

You are right, for this reason, it is not enough to display data on the screen. You also need to be able to accurately determine the data type. To do this, you need to perform operations on the data that can only be performed on this data. If you assume that there is a number in the block, then try performing a mathematical operation, if a string - check its length, and so on.