Defining a Variable That Depends on Runtime Elements

Variables are great. Sometimes you can initialize them and include the data as part of the initialization, such as with a hard-coded piece of text (see Figure 6.38). This kind of data is already known before the app starts because it’s right there in the code blocks.


Figure 6.38 A perfectly fine global variable initialization that depends on known information.

However, sometimes you want to fill a variable from data that isn’t definitely known or that is somewhere else, such as in a TextBox. If you try to initialize a variable to include data from a component, it doesn’t work (see Figure ...

Get Learning MIT App Inventor: A Hands-On Guide to Building Your Own Android Apps now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.