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

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 How to use the “2 Button” Notifier dialog box

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 Tip: Using component colors to find components in the Blocks Editor

“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: