# Text substring function crashes?

**URL:** <https://community.thunkable.com/t/text-substring-function-crashes/757273>\
**Category:** Questions about Thunkable X\
**Created:** [August 20, 2020, 6:23pm UTC](https://community.thunkable.com/t/text-substring-function-crashes/757273 "2020-08-20T18:23:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrtwocanes](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mrtwocanes/32/32268_2.png) [@mrtwocanes](https://community.thunkable.com/u/mrtwocanes)\
**Post date:** [August 20, 2020, 6:23pm UTC](https://community.thunkable.com/t/text-substring-function-crashes/757273/1 "2020-08-20T18:23:30Z")

</div>

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

 ![Screenshot from 2020-08-20 11-15-18](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/0/c00651530aef3f0a22593407edfdbd2f54a7ff71.png)

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?

---

<div class="post-metadata">

**Author:** ![actech](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@actech](https://community.thunkable.com/u/actech)\
**Post date:** [August 21, 2020, 6:38am UTC](https://community.thunkable.com/t/text-substring-function-crashes/757273/3 "2020-08-21T06:38:18Z")

</div>

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

![изображение](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/4/f47f40a26cb6020b11c05ecd622911a84451c397.png)

---

<div class="post-metadata">

**Author:** ![mrtwocanes](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mrtwocanes/32/32268_2.png) [@mrtwocanes](https://community.thunkable.com/u/mrtwocanes)\
**Post date:** [August 21, 2020, 8:07am UTC](https://community.thunkable.com/t/text-substring-function-crashes/757273/4 "2020-08-21T08:07:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![actech](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@actech](https://community.thunkable.com/u/actech)\
**Post date:** [August 21, 2020, 8:13am UTC](https://community.thunkable.com/t/text-substring-function-crashes/757273/5 "2020-08-21T08:13:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 12:24pm UTC](https://community.thunkable.com/t/text-substring-function-crashes/757273/6 "2024-11-08T12:24:42Z")

</div>


