Create dynamic collections inside a loop

Hi, is there anyway (or sth similar) to dynamically create different collections inside a loop. If I want to loop through these keywords then I want to add it to a corresponding collection instead of having every output of the keywords in one single collection.

Keyword1 to a collection named “listpage(Keyword1)” for example

So I can reference the collection dynamically when I add the data row to a table as well

@yeeterminator
welcome tot the forum

we feel that we can give a more close answer when referring to some more detailed samples

@yeeterminator

As per your requirement it looks like you need a collection of string and collection again…this way it would be dynamic for you

Collection(of strinng,collection(of string,object))

Here the inner collection is the collection of sets and outer collection is like your dynamic collections group

Cheers

Thank you for your reply. I was only able to add one picture. If I loop through the three keywords, “Keyword 1”, “Keyword 2”, “Keyword 3”, what ended up happening is that it adds all the instances that keywords appeared in the PDF pages into “a single collection”

I want it to add to separate collections. Keyword 1 to collection 1 Keyword 2 to collection 2 and so on

so when I reference the collection during the “Add data row activity” it will output sth like

File Name | Keyword 1 | in which page the keyword appears in (Ex: 3, 5)
File Name | Keyword 2 | in which page the keyword appears in (Ex: 1,2)
File Name | Keyword 3 | in which page the keyword appears in (Ex: 10)

the problem I currently face is that it adds all the pages together since I only have one collection (listPage) so my current output look sth like this. If I have separate collections then, when I add the data row it should be independent instead of combining all instances where the different keywords appear together

File Name | Keyword 1 | Appears in 1,2,3,5,10
File Name | Keyword 2 | Appears in 1,2,3,5,10
File Name | Keyword 3 | Appears in 1,2,3,5,10

Best way would be with a dictionary. Create a variable as datatype Dictionary(Of String, List(Of String))

Then you can manipulate each list in the dictionary the same way you would any other list, just by referencing the key. For example…

Assign myDict(“Names”) = {“Paul”,“Tom”,“Larry”}

String.Join(“,”,myDict(“Names”))

with the second explanation, we can recommend focusing more on the use case and defining it more sharply without mismatching with implementation constraints. This will avoid an XY-Problem creation.

Once the the overall goal is cleared we can check for strategies and appropriate datatype/structures.

So, dictionaries, JSON, DataTable can help.Also it is possible to create intermediate results and transform it into final results. Depending on the loops maybe some info are not needed to get stored within an intermediate result (e.g. filename).

with a variation of Paul’s suggestion in a flow like

Assign Activity:
myDict = KeyWordList.ToDictionary(Function (x) x, Function (x) new List(Of int32))

For each Activity | kw in KeyWordList

  • If Activity | Condition: result.toLower…Contains(kw.toLower…)
    • Then: Assign Activity - myDict(kw) = myDict(kw).Append(int32PageNoVar).toList

we do have some starter help

2 Likes

thanks for the XAML. At the first look and along with the above discussion we do feel that the implementation can be much condensed. But with:

the elaboration is still missing

Hi Peter, I was able to succesfully solve it. Thank you so much

@yeeterminator Then mark the respective post of @ppr as a solution!

Regards,
Ajay Mishra

It would be good if you would explain how you solved it so your solution may help others.

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