2015년 1월 7일 수요일

Reading amount of files by the File component.

    I need to read an amount of text files representating graphic data (just numbers) for draw them on canvas. 
    Problem comes when I'm trying to read files in "for each item in list" loop from a list where are stored a names of files. Each time when file is readed, a readded data are stored in other list in pairs - a file name and data by "File.GotText" block. Here, since in GotText blog is missing argument which contains name of readed file so I added global variable where im storing the file name after it is readed. But, When i view full list containing the file names and their data I get in whole list of same name of files (that one last one in list) but data are stored right. (Example in an attachment).
    I really dont understand why It doesn't work. I'm sure, that global variable containing actual reading file is rewrited each loop right. (look at attachment containing a printout of debug info - Screenshot)
    Also I don't understand why I have to click 2-times on refresh button for view list with stored data, if It shoud do at first time already.

    Could anyone tell me where I'm doing mistake or how the File component actually works?






you are trying to read all files the same time...
the file component works asynchronously, which means, you should 
1. read the first file, in the FileGotEvent do something with the text you received from the first file, then 
2. read the second file, in the FileGotEvent do something with the text you received from the second file, then 
3. read the 3rd file, in the FileGotEvent do something with the text you received from the 3rd file
4. ready

see also this similar example (well, there the web component is used, but the logic is the same) https://puravidaapps.com/filebyfile.php



I reworked it and it works already! Thank you for your help Taifun!
Adding solution in attachment:



Writing A List In A Label

I'm looking to write all the values in a basic list(with values like 10,22,34,46) and want to write it in a label like so

Building 1: 1
Building 2: 22
Building 3: 34
Building 4: 46

I'm looking to do it in a little code as possible.



You'll want to use a for-loop or a while-loop to iterate over the list. You can look up the documentation for these on the app inventor site.

Please post a screenshot of the blocks you have written. Then we will be able to help you make it more efficient (use less code).

Thanks and happy apping!


Webviewstring to Javascript Array

Ok. I don't kno how, but I messed up my original html file somehow, and I can't revert it back. I don't know what I changed. and I can't transfer my list to an array of arrays in Javascript. I did that once, it worked to perfection, but I can't re-do it now. I haven't changed the source, just messed up some code in my blocks or my HTML. Whatever happened, I decided to get this sample into my computer and try to play with it to learn: PuravidaApps: Table

 Firs I run it as it is, it works. next, I added a web1 and called for my data. It gets the data and I changed it so it will send my data, which comes as a csv table, to webviewer. It shows everything correctly, in the table. as you can see in picture 1. 

but WHen, I try to access a single item from the array, it treats the array like a string and gives me just one character. Here is what I wrote as a script:
<script>
document.write(urlArray + "<br>");
document.write("first item " + urlArray[0][1] + "<br>");
document.write("second item " + urlArray[1][4] + "<br>");
document.write("third item " + urlArray[2][3] + "<br>");
</script>

In picture 2, you can see what it brings out. I've been trying to solve for a day now, and about to go nuts! Please show me what I'm doing wrong. And also, I don't understant how the table is actually filled with items all sorted when I can't access them with code. Thanks..





urlArray is not a 2 dimensional array, see the relevant parts of the code below
Taifun

    var urlArray = window.AppInventor.getWebViewString().split("\n");

    for(i=0;i<urlArray.length;i++){
      // split at comma
      var rowArray = urlArray[i].split(",");
    }




any idea how I was able to do that before? I wish I hadn't changed any part of this. Whatever, Is there a way to change it into a two dimensional array?




one method is to pass the data as JavaScript array to the html file, see this example https://groups.google.com/d/msg/mitappinventortest/pVA3VUMN5W8/pZLttKYl3-8J



if anyone searches for a similar information, I want to write the solution I figured.. The "list to csv table" is NOT allowed to become a 2d array. What you need to do, is to code the entire message with the block style you can find at Taifun's web page here. In my example, I got the data from my db, then converted it to a list using "list from csv table". Then, I added every item together like this:

item1,item2,item3\nitem4,item5,item6\nitem7,item8,item9

you do this by joining them together as text strings. Then you transfer this to your webviewer, and define it an array. Then, define another array an make it equal to "your first array[0]". thisway, you don't still get a 2d array, but you just get arrays, which can later be merged into a single 2d array. 

Taifun, your examples make us better rookies. Thanks.


Where is TinyDB file stored?

I am getting a new phone and would like to transfer the existing information in a TinyDB to it.  Where is the database located in the phone?  I've looked in many directories, but can't find it.



see here https://groups.google.com/d/msg/programming-with-app-inventor/r20fH5D0dBY/hX-qFrR6LfsJ


Highlighting text in a text box

One of my students is creating a note taking app and would like the user to be able to highlight the text entered into the text box. I don't see an option for that, but I'm wondering if anyone else has a more definitive answer.



you are correct, there is no such option



AI can not do that but the user can double touch the textbox to highlight

like this:





On the emulator, you do it with a double left mouse click; on a device you do it by a rapid double touch.

This this work for the student?