Tag Archives: stem

Implementing an “Array” in App Inventor

What is an “Array”?

An array is a variable data type that stores a collection of values referenced by an index number.

For example, suppose we wished to store the names of the 12 months of the year: January, February, March, … , November, December so we can convert a month number to a text name. Month 1 converts to “January”, Month 2 converts to “February” and Month 12 converts to “December”.

An easy way to do this conversion is to set up an array that, in concept, looks something like this:

Month[1] = “January”
Month[2] = “February”
Month[3] = “March”
Month[4] = “April”
Month[5] = “May”
Month[6] = “June”
Month[7] = “July”
Month[8] = “August”
Month[9] = “September”
Month[10] = “October”
Month[11] = “November”
Month[12] = “December”

Month is the name of this variable – but unlike other variables, this one stores 12 separate values. Each value is referenced by using an index – if the index value is 2, then Month[index] refers to “February”.

If we have a date, such as (US-style) – 2/14/15, meaning February 15, 2015, we can convert the month number of 2, into the text month name by referencing Month[2].

If you have studied algebra math or beyond, you have encountered array variables such as X1, X2, X3, … Xn where the value Xi is read as “X subscript i”. This is the same concept as an array of values. If you have not studied algebra, this notation may be new to you. 

Most programming languages support an array variable type but App Inventor does not support arrays. Yet arrays are a convenient way of storing and working with some types of data. To support an array-like variable in App Inventor, we can use a list and map the array subscript to an index position in the list.  By hiding this within a couple of procedures, we can simulate the array variable type.

Sample User Interface

I created a simple app to demonstrate the use and implementation of the array. You can download this app from the MIT App Inventor Gallery here.

Continue reading Implementing an “Array” in App Inventor

How to use the “2 Button” Notifier dialog box

A reader asked, “When using the 2 button Notifier dialog, how do we know which button was pressed?

The 2 button Notifier dialog alert box displays 3 buttons(!) – the first two have values you specify, such as “Ok” and “Done”, as shown here, and the third is an optional generic “Cancel” button:

Screenshot_2015-09-11-15-07-15

The Notifier component block is a procedure call that has no return value – so how can you determine which button was selected?

The answer is that the selected button is returned to a separate event handler.

Continue reading How to use the “2 Button” Notifier dialog box

Tip: Using component colors to find components in the Blocks Editor

Finding a specific programming block with in the AI2 Blocks editor can be hard for new AI programmers.

You found a great code example online and want to recreate it by entering the blocks in to your program – but you cannot find that red block in the middle of the code sample? Where is it? !!!

You start poking around the drop down lists, scanning up and down the pop up menus, missing it the first time(!) and then going through all the blocks again until you finally locate that darned block! Frustrating!

Continue reading Tip: Using component colors to find components in the Blocks Editor

App Inventor 2: Databases and Files – available shortly

Volume 3 – focusing on TinyDB, TinyWebDB, Fusion Tables and text files – is now Available.

————————————————————————-

App Inventor 2: Databases and Files is a step-by-step guide to writing apps that use TinyDB, TinyWebDB, Fusion Tables and data files for information storage and retrieval. Includes detailed explanations, examples, and a link to download sample code. This is the first tutorial to cover all of these App Inventor database and file features.

If your apps need to work with data or files – you need this book!

TinyDB stores data on your smart phone or tablet and is a primary way for App Inventor apps to save data, even when the app is no longer running or if the device is turned off.

TinyWebDB is similar to TinyDB, but stores your data on a remote server in the network cloud.

Multiple apps can share a TinyWebDB database, plus you can update the content of your TinyWebDB using just a web browser. This means you can distribute an app whose content can change over time – just by changing the values in TinyWebDB.

A big challenge is the need to set up a TinyWebDB server – this book shows how to do that through free services offered by Google.

Fusion Tables provide a powerful, cloud-based database system for App Inventor apps. Creating, retrieving, updating and deleting data is done using the industry standard Structured Query Language or SQL. Fusion Tables reside in the Google network cloud – this book shows you how to set up and configure Fusion Tables for you own apps using free services of Google. As your app requirements grow, Google’s cloud can provide low cost servers and bandwidth for your needs.

Underneath the Android OS user interface, there is a file system, similar to the file system found on Windows or Mac OS X. With App Inventor your apps can write and read data from files, and if using the special “CSV” format, App Inventor data can be shared with many spreadsheet programs. This book shows you how to create, use and access data files, and how to convert data to and from the CSV format.

Over 28,000 words. Amazon’s page count is 322 pages. Over 250 screen shots and illustrations. Numerous sample programs and code.

App Inventor 2: Databases and Files – Table of Contents
1 – Introduction
2 – Using the TinyDB database
3 – Implementing Records Using Lists in TinyDB
4 – Simulating Multiple TinyDB Databases
5 – How to Use Multiple Tags in TinyDB
6 – Introduction and Setup: TinyWebDB
7 – Managing TinyWebDB in the Cloud
8 – Programming for TinyWebDB – Demo 1
9 – Adding a Tags List to TinyWebDB – Demo 2
10 – Handling Multiple Users with TinyWebDB – Demo 3
11 – Implementing a Student Quiz Application using TinyWebDB
12 – Introduction to Fusion Tables
13 – Developing Your Fusion Table App
14 – Using Text Files in App Inventor

“Why Learning to Code is So Damn Hard”

Click through for the full post at Viking Code School – as they say, the early part can be easy, then things get tougher, followed by a challenging learning period – until confidence and skills flourish.

What every beginner absolutely needs to know about the journey ahead

Source: Why Learning to Code is So Damn Hard

MIT App Inventor makes many things easier – but eventually one must learn to think like a software developer and become familiar with concepts like data structures, algorithms, design patterns, and software engineering design and project management.

Using TinyDB in App Inventor

(This post was completely rewritten and updated on October 30, 2015)

What is TinyDB?

TinyDB is a simple “database” that stores data on your phone or tablet. Unlike program variables that go away when your app is finished running or your phone is re-set, values stored in TinyDB remain on your phone for use the next time your app is run.

About Memory on your Phone or Tablet

Your smart phone or tablet typically has two primary types of memory: RAM and FLASH memory.

RAM stands for “random access memory” – but today we mostly think of RAM as memory that can be accessed very fast (as compared to Flash or hard drive memory storage). RAM retains values as long as power is applied to the RAM circuity. Once we turn off the power, the values stored in RAM are lost. (In some applications, extra batteries are used to continuously provide power to RAM even when the “normal” power is turned off.)

Flash memory retains values when the power is turned off. But access to Flash RAM is not as fast as access to conventional RAM memory.

Why is it called “Flash”?  There was an early version of memory technology where the memory was erased by literally flashing it with ultraviolet light. However the inventor of Flash RAM chose the name “Flash” for different reasons. Modern Flash RAM is read, written and erased electronically.

App Inventor variables are stored in RAM memory – and the content of RAM is erased or reset whenever the power is turned off. TinyDB, on the other hand, stores values in FLASH RAM, where the values remain even when the power is turned off.

Using TinyDB

TinyDB provides a simple way to store and retrieve data efficiently and to store the data in long-term storage.  TinyDB is based on the concept of a “tag” to identify the stored data, and the data value. Think of a “tag” as like using your name as your identification to look up your address:

Tag value: Martin

Value: 123 Main St, Anytown, USA

or

Tag value: Alexa

Value: 321 Other St, Someplace, USA

TinyDB uses the “tag” (such as Alexa) to quickly locate the corresponding value. Even if you have 100 names and addresses stored in TinyDB, TinyDB can  look up the “tag” quickly and use the tag to find the corresponding value. We do not need to know how TinyDB does its look up so fast – it just does it [see Footnote 1].

In most database programs, the “tag” is known as a “key” or “key value”. App Inventor uses the name “tag” in place of “key”. As I am used to the name “key”, I tend to use “key” were I should have used “tag” in App Inventor! You will see this is the sample program, below!

To learn how to put TinyDB in operation, we construct a very simple app, described below.

Continue reading Using TinyDB in App Inventor