2014년 12월 2일 화요일

read from file

ok so i can save text to a text file using file block. there is a read from file block and a when file got text block. how do i use these blocks to read the text from the file and display it in a text box??



set Textbox1.Text to File1.ReadFrom "myFile.txt"


ReadFrom(text fileName)
Reads text from a file in storage. Prefix the filename with / to read from a specific file on the SD card. for instance /myFile.txt will read the file /sdcard/myFile.txt. To read assets packaged with an application (also works for the Companion) start the filename with // (two slashes). If a filename does not start with a slash, it will be read from the applications private storage (for packaged apps) and from /sdcard/AppInventor/data for the Companion.



You should use the GotText block

Set  TextBox1.Text  to File1.Text



found it file got text block didnt realise when you hover over the the small square saying text it gives the get text box. sorted :-)



I think i have the same (or similar) problem. I have a csv file contains more than 150 data. I want to read data from that file and write to a label (or text block). I found some workarounds for this issue but i couldn't find any sample/tutorial for the usage of "file" block. Is there any sample?



@Bob: so why don't you just try what I recommended to use in this thread?
set Label1.Text to File1.ReadFrom "//myFile.txt"
To read assets packaged with an application (also works for the Companion) start the filename with // (two slashes) 



Finally, i read the file with defining the file name as /AppInventor/assets/File.csv . It worked.

But i guess i have another logical problem. My "File.csv" document is on my phone. When i compile the code and send to another phone, program try to get an item from empty document and fails. So, can i use File.csv in another phone after compiling.



upload your csv file as asset into your app, then use this path to your csv file
//File.csv
To read assets packaged with an application (also works for the Companion) start the filename with // (two slashes) 



can u upload an image of ur work plz
?!!


댓글 없음:

댓글 쓰기