Replace in a List created with csv file

Hello,

I have listview that I created with a csv file, with 19 indexes (list1) and other list created with colin tree only with 3 indexes (list2).
Is possible for each element of list 1 if they are in list2 (in index2 of list2), replace each element for the text “yes”?

Many thanks

This forum discussion might help you Replace one item of .csv file
to replace elements.

How to work with Lists bySajal shows how to replace values in a List. What you say you want to do.

Also this article might help you Programming Lists of Data .

What have you tried so far?

Regards,
Steve

Hello,

  1. I have a list of countries that are selected and stored in tiny db (list 2 mentioned above) - see attach 11 - list2-stored tinydb

  2. and i’ve a wish list created thru a csv file (list 1 mentioned above) - see attach 2
    2 - list 1 - csv list

step 1 and 2 are working ok!

  1. if countries in list 1 (csv list) are in list 2 (tiny db list), i want to replace only these countries in the list created with csv file with the text “YES”
    For example if my list 2 (stored in tiny db) has Australia, Canada, India i want to replace the values that are shown in the list view created thru csv list with “YES” - please see attach 3 -

  2. This is what i tried to do but it’s not working - attach 4, most probably not the correct way
    4 replace blocks

These two samples might help …

Hello,

I’m trying to understand how to apply these examples to my case, and i’m not sure how, because the layout is very different.
The first step that i needed your help to understand is how to find the “n” values stored in one tag in tinydb (selected country names) in another list that is already vertical, separated by \n (like suggested in the docs sent), etc … than identify by changing that text and keep the others like before.

example: before i’ve
Benjamin
Gold
Business
3
France
Spain
Australia
(none)
(none)

because Australia is stored in tinydb, the new list should be:
Benjamin
Gold
Business
3
France
Spain
YES
(none)
(none)

Please Help ! TY

What does the yes/no mean? That the person wants to visit that country, or already has visited it?

Your program is made harder to design because your data design is not normalized.

You need at least three tables for this …

  • A list of names, with their category and subcategory (3 columns), key = name

  • A list of country names (key = country name), (1 column) for reference

  • A list of (name, country) pairs with that yes/no value you want to keep, (3 columns) key = (name, country name).

This design makes it easier to filter the tables using designs like in https://docs.google.com/document/d/12t4HLNRepCnbmcfycdF8wSHWht_D1P8hKJpTknVDChY/edit?usp=sharing

If you have not yet done so, search the web for articles like Introduction to SQL to learn how to think in sets of records and tables.

Instead of marking up your original data tables, think in terms of filtering out temporary tables matching your search criteria. It makes for easier solutions.

Hello,
I will try to split in more than 1 list.

My issue, is that i dont want to filter or add a new list if the values are stored, like the examples sent before.

I want to keep the initial list - lookup for the values (countries) in csv list that are stored in tinydb - and replace them.
That is essential, because after i will like to count the number of “yes” for each name (key).
Probably i can do with the filter and than with the same key text do the sum of the count of each list.

Well first i’m going to do what you suggested, split my initial table, and try to lookup for a solution that gives me only the values stored in tinydb.

Thank you !

Hello,

I decrease my list and tryed to do all of the suggestions, for all i’ve the same error

a1

a3

Taking into account your last suggestion, i did the following blocks:

Please help taking into account my example.
It’s the first time that i really dont understand what is missing or what is the error, when i ask for forum help.

Because i already tryed all the suggestions, and i always get the same error. I need to understand what is the issue with probably the index.

Note - i just want to see the results in the list, i dont need to do a after selecting (list item)

Many thanks!

The error is in the operation select list item … the format shown in the error message does not appear to be a List. This suggests one of your elemento is NOT a List.

You do not provide a link to your Google Sheet or an aia file. Because you did not provide that information, only you can test and debug. The error is introduced in one of your select list item input Blocks. Which one? Sorry I certainly do not know.

You can find out where the problem is by using the DoIt debugger and by temporarily disabling some of your code one block at a time. Disable code, then run the app. When the error message no longer appears, you found the Blocks that are causing problems.

How to debug might be worth reading.

Good luck. I hope this helps.

Regards,
Steve

Hello,

doesn’t because the feedback is the same i already have. I know something is wrong but what this message means? because when i do the debug i get exactly the same info, not the solution or something more detailed, it’s really frustrating

when i convert the csv to a list in the first step with index 1,2 and 3, the list shows and it’s ok. I dont understand why doesnt accept and gives a value to select list item index 2, if before the list shows.
Doesnt make any sense!

OK … some things to try

Show us what a a print out of this List ‘when i convert the csv to a list in the first step with index 1,2 and 3, the list shows and it’s ok.’ looks like. Perhaps the csv is not converting properly.

Local variables may look nice in a coding class but they make debugging difficult. What you might do is instead of evoking your format Procedure (incidentally, format may be a bad label for a Procedure…try myFormat); try this

doIt

and do a DoIt and see whether it returns true or false.

In your case, I believe it will return false (but I don’t know what your Web component is returning.)…you can find out. Use some code like this to perform a test to see what the first item in your List actually is.:

Web

What does the test tell you about the first element?

Once again, possibly a poor choice for the name of a variable (table… mytable is better) ; while not
in a list of reserved words for Java, the word might be reserved in AI2

This note may help other developers… Java ‘reserved’ words… avoid using these in renaming controls, procedures etc.

abstract continue for new switch
assert default goto package synchronized
boolean do if private this
break double implements protected throw
byte else import public throws
case enum instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp volatile
const float native super while

from https://androidheight.blogspot.com/2015/06/what-are-keywords-datatypes-variables.html

You might also try this (although I am skeptical it will work in your case)
Un check this block if it is already checked in Screen1 Properties

jsonList . Checking the box could be causing issues when using text blocks. A huge guess.

1 Like

Thank you so much Steve for the help.

I did the test and it is a list
The suggestion of the labels to test the index is great, and now i see / identify the problem but still strange.
When i do add items to the list, the list does the split by colums, i did a check taking out index 2, and when i set up the list doesnt show the values of the 2nd column.
When i do select list item the result is the rows, if i choose index 2 returns row 2 = column 1 + column 2

Do you know why ?

TY

I unable to debug your code Neusa just by inspection and your description.

Here Is what I think you are trying to do

The code uses three of your csv rows. It filters and selects all instances of Australia by row (column I2 in your spreadsheet). Change the term Australia for any other country to search based on a different country.

Reproduce the blocks, confirm this is what you want to do and use the blocks in your Project if appropriate.

Your problem is in one or both your Procedures. I do not know why since I cannot test your code. Notice, I did the comparison in a different way than you tried.

Regards,
Steve

1 Like

Hello Steve, solved ! Many thanks, without your help i wouldnt get there, or would kill my brain trying to get an alternative.

… Ty ty ty

1 Like

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