returning a list of items from lookup in pairs

1,281 views
Skip to first unread message

Scott Ferguson

unread,
Oct 10, 2015, 9:59:15 AM10/10/15
to app-inventor-de...@googlegroups.com
The List block lookup in pairs accepts a key 'word' (it can be a number also) and returns a value from a specially formatted list.

Related to a support request, this extension of that response is a little project snippet to demonstrate how you can use lookup in pairs to search for a keyword and return a list rather than a discrete value.

The premise is that the user enters a Catalan word and the app then returns either a Spanish or French translation of that word.

The Catalan words and their corresponding translations are stored in a text CSV table file, test4.txt:



Here are the core blocks to accept a Catalan word and return either a Spanish or French translation:

The steps are as follows:


The text of the test4.txt file is read with the File1.ReadFrom procedure.

The File1.GotText event block then converts that text from it's CSV table format to a pairs (nested) list with the list from csv table block and stores that in the CatalanToOtherLanguages global variable.

The lookup in pairs blocks show how to select a specific Catalan word and have either it's Spanish or French translation returned.

A search for 'Catalan5' returns a two-item list containing the Spanish and French translations.

The select list item block is used to return either the Spanish or French translation.

The Spanish translation is item 1 in that list.

The French Translation is item 2 in that list.


For applications where an item in a value list is not a number or text, you can build the pairs list manually using the last of these three methods:


---

sf










Reply all
Reply to author
Forward
0 new messages