I've successfully been able to use CSVtoList to create and return key value pairs, but I'm currently trying to create part of an app that can take a CSV file and turn in into a dictionary, where the first column of a row would be the key, and the subsequent columns would be all the associated values. When I search for that key I could return the associated values. Take the following example of a sample CSV table:
I would like to convert that into a dictionary where I could search for the UPC key and return all the values for that row (description,cost,price), or possibly any value I choose, though I know the latter would be more complicated.
I've seen a lot of posts about dictionaries but they all seem to being doing something slightly different than what I need, and I'm having a tough time figuring it out. Is there possibly a better way even? Thanks for your help in advance.
That structure looks like it might work and it makes sense when set up manually as you've done it. But I'm trying to import the CSV from a file and have it populate the dictionary with the UPCs set up as keys.
Here is an example of a screen that I'm working on:
I can handle the formatting of the output data, but really I just want it to output the rest of the row essentially when the UPC is entered. Does that clarify it? If what you showed me is correct and it's trivial to have the dictionary set up from a file instead of imputing all the entries manually, I'm just not seeing it. Thank you for your help thus far.
You do not need to go to all the trouble of creating and working with dictionaries, you can do this with your csv table converted to an AI2 list.
Here the blocks get the data from the csv, then set a listpicker items with the UPCs
On selecting a UPC, the additional data can then be displayed ( I haven't done any formatting work on the three items)
Oh, I thought I might have be thinking about it the wrong way! This is exactly what I was trying to think of. I'm used to SQL so it's hard for me to not just be able to write a select from table where.... I will try this out and let you know how it works. Thanks so much for your help!
OK, I guess I'm still a little confused by your example. I don't really understand why there are 3 separate label.texts being set. Shouldn't it just be one for the output? The UPC is an input, and there would be one output as far as I can tell. Could you possible post an .aia file so I could see how it works?
Your previous example seemed like it would work, I just don't understand why there are so many labels being set without looking at an aia file. I'll look into the SQL lite options as well. It just seems like overkill for a simple key/row lookup for a single table essentially. I would have thought this would be trivial. I guess I'm a little out of my element.
OK, I know I'm being bothersome at this point, but listpicker for UPC is probably not an option. There will be upwards of 30,000 UPCs in the actual use of the program. Is this possible with a search? On the screenshot of the UI that originally posted, the lookup code triggers after something has been entered in to the UPC field and it loses focus.
This sample will load your little table at startup, though I have no timing data for how long it would take for 30,000 rows.
If it's too slow, you could instead load TinyDB NameSpaces, one per column, tag = UPC code for all of them, just on the first run. CSVToDict.aia (3.4 KB)
This would be a person scanning an item and then having the product description pop up. The scanning aspect is already solved, the dictionary lookup is what I was concerned with. Thanks again for your help, I feel ABG has given me the correct solution.
Yeah, I actually tested it with a 60,000 row CSV file and the lookup on the device that I'm using took about .6 seconds, so I don't foresee that being too much of an issue. It's really more for the user to know whether or not the item has been set up in the back system that provided the CSV file in the first place. Your solution looks perfect. Thanks for your help.