A function returning file contents?

I am not very well. So I couldn't send it.

One of my degrees is mathematics... It is always nice to have an existence proof up front, before spending huge amounts of time proving the theorem.

Did you manage to find an answer or not get around to it?

I said

Let me answer simply.

In the entire history of AI2 no one has done a synchronous file read.

I have monitored the help board, over its history, so I use that to answer your question with a "no".

you have to read my previous answer in the context... you said "The alternative is to split a very large block into many blocks all containing huge amounts of duplicated processing" so if you follow the DRY principle of programming you already know, that duplicating blocks is NOT the way to go but to use procedures.

You are looking for "a function to return the contents of a file as a list"
Later you said "The result is required inside a loop which is inside another loop."

Let's assume, someone is so kind to provide a function to return the contents of a file as extension for you... then this is a fake solution, because reading a file always takes a little bit of time... and to use this inside a loop, which is inside another loop might result in a runtime error after a while, because the processing is blocking the UI thread...

As it already has been said several times here in this thread, in the App Inventor world this is not the way to go. You have to think differently... I like what @ABG said earlier

so for your project let me summarize what we know after 63 contributions: you have some files which have to be read and some processing must be done... your screenshot you provided earlier is completely useless, you already know it...

if we take the analogy of the factory, the raw material will be delivered by trucks separately (these are your files), the trucks will be unloaded and the material will be stored in the storage unit (which means each file will be read and stored in local storage, this can be TinyDB for small data or SQlite database of more complex data)... the delivery of the raw material is independant of the processing later...

then when we start our processing, for example to build our car in the factory, we get the raw material directly from the storage, we only have to make sure, that all the material we need is there... what we do not want to do is to send the guys for example to the tire truck, unload all the tires until we find the AT tires we are looking for and then mount them onto the car...

I hope that helps to start thinking differently...

You finally might want to follow the guide How to ask a question (open new topic) and provide the missing information which is needed to get better help.

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

2 Likes

App Inventor does not do that in a single function - I think you were saying you also needed the ability to read the file line-by-line or 'until' as you can in C/C++ for example.

Bear in mind that this is a free App development program, primarily educational, aimed at young people learning to write code for the first time using a novel interface first developed by Google. Our Technical Support is also free, we are unpaid volunteers - so you get a lot for your money. There isn't a programming language that suits everyone and everything, hence there are so many of them.

If App Inventor does not meet your needs and you don't want to help us enhance it, there is no need to rave here - use Java, Kotlin or one of the fringe languages like Spider Basic, B4A etc that have that functionality.

The last few posts finally admit to the problem I have been trying to point out. I had already concluded (in a post two days ago) that java was likely the answer since AI2 chooses not to handle this. Should somebody actually decide that it should be handled, I suggest going back and looking at the old tcl/tk (another free user-supported tool) event loop where a solution to this problem has existed for decades.

In the absence of a concrete example (that you didn't provide despite repeated requests :upside_down_face:), no one (except possibly yourself) might have learned anything from this topic.
(At least I don't.)

1 Like

From this thread everyone could learn the following:

  1. How to ask a question (open new topic)

  2. here in the App Inventor world you have to think event oriented

  3. https://www.goodreads.com/quotes/620163-the-more-i-learn-the-more-i-realize-how-much don't know

Taifun

3 Likes