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:



댓글 없음:

댓글 쓰기