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

Tip on inserting images into Microsoft Word

Off topic a bit but this may be helpful to others inserting images into Microsoft Word documents or trying to create better images in e-books.

E-Book Images

The past few days I have been looking at ways to improve the image quality in e-books. Images are not handled well by e-book development software and some of the problems are due to undocumented “features” and software defects.

Three common file formats for images are JPG, GIF and PNG. JPG images are good for photos but not great for drawings (like App Inventor block code). However, Amazon secretly decides on its own whether or not one’s JPG images are sufficiently compressed and makes its own secret decision to recompress the original JPG even more, losing resolution in the e-book.

Images that start as PNG files are converted to JPG files by the software that creates the e-book formatted files.

GIF files go through the process “as is” and remain as unchanged GIF files. GIF files are best for drawings (rather than pictures) with lots of solid colors. Therefore it is best to use GIF files for illustrations such as App Inventor “blocks code”.

The basic rule for e-book authors is to use JPG images for photos and GIF files for drawings and illustrations (non-photo images).

Microsoft Word Turns Inserted Images into Blurry Images!

Today I discovered Microsoft Word converts clean GIF images into blurry images when GIF files are added to a document.

I was working with a document that had older images, captured and inserted differently some time ago. Those images looked nice and sharp. But when I imported new GIF screen captures, the new images looked soft and fuzzy. Word is converting (and recompressing) the imported GIF files and reducing their image quality. There is no way to turn this “feature” off in Word! This “feature” creates images that are unsuitable for e-books or printed book use.

This is a “known defect” (“feature”) introduced by Microsoft Office Word in 2010. I discovered this on Mac OS X Office 2011. The work around is save your Word document in the older 1997-2004 .doc file format. Now, when you insert images into the file, they appear correctly.

This is documented in a Microsoft forum here. Related issue in MS Powerpoint.

Afterword: I also tried OpenOffice, which I like, but ran into other problems there such that OO was not a solution either.

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

Poll: Do you prefer printed books (cost more) or ebooks (cost less)?

Some of my readers have asked about printed copies of my App Inventor e-books.

There are services available that can print high quality, full color (with more detailed images) “on demand” which means a copy of the book is printed and manufactured at the time of purchase.

Printing adds cost. Depending on the size (height and width) and length of the printed book, prices might fall in the range of US$10 to $20.

Are you interested in printed books or are e-books okay with you? Here’s a quick poll on the subject – this poll also appears in the lower right side bar of this web page.

Thank you for your help!

[poll id=”3″]

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

“App Inventor 2 Databases and Files” ebook now available, 322 pages

For a complete description of Volume 1 (Introduction), Volume 2 (Advanced Concepts) and Volume 3 (Databases and Files), please see my App Inventor 2 e-books page where you can view the table of contents, download a sample chapter, and find links where you can obtain these ebooks online at Amazon, Google Play, Kobo Books and so on.

  • Volume 3 covers TinyDB, TinyWebDB, Fusion Tables, Files and exchanging data with CSV format files.

Volume 3 is a big e-book – 322 pages long, says Amazon’s page counter.

Volume 3 is now available at

Links to all 3 books are available here.

Capture

My Guide to 3D Photography e-book is available from:

How did you discover MIT App Inventor?

How did you discover MIT App Inventor?

I discovered App Inventor just as Google was handing AI classic off to MIT. At the time I was looking at different kinds of development tools for mobile devices, and App Inventor showed up in some online searches.

I took a look at it and found it  intriguing – at the time, AI classic did not seem quite capable of doing the things I was likely to need, but I intended to keep an eye on it.

A few months later, I was asked if we could quickly train some high school students to write Android apps? I have been a volunteer engineering mentor with FIRST Robotics programs for eight years. The new high school team where I was volunteering had intriguing ideas for mobile apps. When I was asked about the feasibility of quickly building some Android apps, I immediately proposed MIT App Inventor!

Our first student was so enthralled he literally stayed up half the night teaching himself App Inventor and soon was writing bundles of code for our Android tablet applications. Eventually another student joined the effort (from an iPhone background!) and rapidly came up to speed, writing a neat app in App Inventor.

Continue reading

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