Lists and variables

I don’t want to delete a sublist, I want to overwrite its parameters, replace the old values with the new pnes.

Very good

Which means, you like to replace a sublist
Use the replace list item block to replace sublist n with another list of 10 items

http://ai2.appinventor.mit.edu/reference/blocks/lists.html#replace

EDIT: to clarify, you do not have to replace each item of the sublist one by one, just replace the complete sublist in one statement

See also Imagnity.com List Tutorial, Mirrored - @Saj

Taifun

Or I can just put the values in the first sublist and everytime i click erase it automatically sets the labels of the test I clicked to the values of the first sublist.
Like i have showed previously. My problem is when I leave the screen I loose all the values except the first sublist because I inialize my screen with it.
How can set test 1 to 10 to always show values.

Store your list in TinyDB and read it again during Screen Initialize
Only on first run of your app read your initial values
How to find out, if you run your app the first time, see also this example App Inventor Extensions: SQlite | Pura Vida Apps

Taifun

That's what I have done I stored it under the tag Setting. I went to the other screen and Initialize my slot 0 that will hold my last values before I click Erase. The moment I click Erase, the values will go to Test 1 ( for example if I clicked the first Erase). Then I have to go to When Screen Initialized and set all the labels that hold the parameters. Since I have 10 tests ( 10 button erase as you can see in the picture above), I can't set all the labels, of all the buttons to a variable.

Why are there 10 erase buttons and what are they erasing? Is each button deleting another sublist of the main list? What about having only one button, which then first selects the sublist to erase (could be a spinner to select between 1 and 10) and then have only one set of blocks instead of ten different, but similar sets of blocks?

Taifun

They are erasing the old values and replacing it with new value. Imagine you have a machine and you don't want to lose the exact calibrage, you store it in test 1, you make another experience you store the values in test 2... Til test 10, now all of them are filled, you want to store new values but the test are full, you erase an old values to replace it with new one.

So "erasing" means

  1. replacing one of the sublists by another list

and 2) displaying the updated data in the user interface

Did you consider to display the data in a table? This would be much simpler with only a few blocks

Taifun

Okey I will try this solution and let you know. Thank you

The replace list with another list do you mean like this? y list where I have my values is the list records, it's an empty list that I filled it with my values from Settings tag, the erase button that should take this values, and put them in a new list, I didn't know how to code it. If you could help me please.

records is your list of lists
But where is the list of new data?

You have to seperate 2 things: 1) the data itself and 2) displaying the data

The first step is updating the data, which is your global varriable records

The second step is displaying the data, remember I suggested to display it as table...

Taifun

records is an empty list. My list of lists is DATA it's in the other screen. Yes now I want a to everytime I click erase I replace either empty/ filled labels with the new values that Are in the list records that is always showing when I initialize the screen. Because I got them from the tag Setting that contains the list DATA that contains list of 10 sublists.
I did my own method that I showed previously but it(s very very long. Just have a look at my button Erase that I coded ( not the last image I showed, before that). If I continue that way for every button Erase, how can I always display my data even when I leave the screen. To store every Label alone under a tag and call gettag when Screen iniliazes and set the label to get the variable stored under it. It's very hard and long.

I asked my professor if he wanted it as table he said no, He said to display it like I showed before.

If you had to display 10 tests and a temporary test where you store your lasts values. And every time you click replace you get this temporary test. How would you do it?

previously you told us, you like to replace a complete sublist by a new sublist

yes, we are talking about that method all the time to simplify it by just one replace list item bock, but unfortunately you just continue using your method, so there is not much I can do now

you are complicating things
also you are using 2 TinyDB namespaces... why that? you only have one list of lists of the complete data... and a new list with 10 items...

I would have a list of lists, which has 10 sublists and each sublist has 10 items
and I would have a new list, which has 10 items

I would use only one replace list item block like this

Tafiun

it looks like you have to go back one step and learn how to work with lists
probably you are confused how I'm using the list from csv block?
this
Unbenannt
is the same like this
Unbenannt2
only the first example is a little bit shorter, isn't it?

from my example screenshot listMain is your list from post 3 Lists and variables - #3 by lyna_mansouri

and listNew is a simple list which has 10 items

remember, what you said earlier

here is again the list tutorial

Taifun

I did my best with this project. I think I will stop here and abandon it, maybe I didn't explain myself well. I know how to work with lists, the lists were never my probleme, The code with a tag and different tags to each test were. I did exactly what you told me to do the first time by using the block replace, and asked for more help in order to set every label with the correct order. then you gave me another idea and I followed it blindly in order for you not to say that i am stubborn and I continue using my idea. However I genuinely appreciate your help. Maybe I can figure something on my own and If i hesitate with something I will open another topic. Thank you.

you did very good and you did not give up too soon... :+1:
I will repeat the most important points

and remember the example blocks from post #49 Lists and variables - #49 by Taifun
sometimes it is a good idea to start fresh...
remember to use procedures and follow the DRY principle... Don't repeat yourself

Taifun

1 Like

Maybe the best is to have 2 layout instead of 2 screens with any of them hidden while the other is visible. That solve a lot of passing parameters problems...

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.