Category Archives: General

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 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 How did you discover MIT App Inventor?

Pre-Announcing: App Inventor 2: Databases and Files-new e-book

Available now: App Inventor 2: Databases and Files

I have finished writing App Inventor 2: Databases and Files, a new e-book providing step-by-step guides to using TinyDB, TinyWebDB, Fusion Tables and Data Files in Android App Inventor programs, including sharing data with spreadsheets.

Continue reading Pre-Announcing: App Inventor 2: Databases and Files-new e-book

Is there a good way to print App Inventor blocks code?

I do not think there is any good way to make print outs of the App Inventor blocks code.

What I do is:

In Windows 7 (also works in Vista and newer version) is to use the Snipping Tool to select a section of blocks code on screen, copy the selection, and then paste that into a Word document. I make several “snips” as needed, to capture all of the code, and paste each into the document. Then I print out the document.

Is there a better way? I do not know but if you have a better solution, let us know in the comments! Thanks!

App Inventor Stores Numbers as “Floating Point” Format

When you type a number, such as “123”, computers convert the text values of “123” into an internal representation used by the computer. There are many possible ways that numbers can be represented inside a computer. For example, the computer could:

  • keep numbers in their original text format “123” (decimal format)
  • convert them into a binary representation (binary integers)
  • a “floating point” representation (floating point or “float” format)
  • or even a “binary coded decimal” (BCD) representation.

Each internal format has benefits and drawbacks, depending on the application. Most computers (and programming systems) convert entered numbers from their original text format into either integer format or floating-point number format.

App Inventor converts values to floating point format. Which is fine, except that you will encounter some odd and subtle issues. As the link below notes, in App Inventor arithmetic, 0.3 + 0.6 does not equal 0.9!

Continue reading App Inventor Stores Numbers as “Floating Point” Format