Solved Postion of my data in Collection

Hi, I have a scenario where I wanted to know the position of my data in the collection. For an example : my collection contains 15 records, and I wanted to know to positions of 3 records.. I managed to resolve it with 3 loops breaking with exception as and when I found my match case and jumping on to another with a counter....

Wanted to know any other simple methods.. Thanks
 

VJR

Well-Known Member
Hi, I have a scenario where I wanted to know the position of my data in the collection. For an example : my collection contains 15 records, and I wanted to know to positions of 3 records.. I managed to resolve it with 3 loops breaking with exception as and when I found my match case and jumping on to another with a counter....

Wanted to know any other simple methods.. Thanks
Hi VinayMurthy,

You could create a customised action by making use of the 'Collection contains value' action and by adding a line of code to return the row index when a search text is found.
 

VJR

Well-Known Member
I am done with collection contains value action, could you please give me more hint on the code and where to have it?
- Go to the code stage of 'Collection contains value' action.
- Find the area in the code where it searches for a value and finds it.
- Add a line of code to get the row index of that collection when it finds a value.
Collections as data tables in Vb.net/C#. So if you do a web search on "how to find the row index of a data table in vb.net" (because the Collection VBO is written in Visual Basic) then you will be able to get the single line of code.
- Once you get the row index you might want to exit the loop and then pass that value as an output parameter back to the calling process.
If you are modifying the VBO action then make sure to make a duplicate copy out of it and then work on it.
 
I tried to modify the code stage in collection contains value, but no luck as I don't know vb.net coding..
 

Attachments

  • CodeIndex.PNG
    21.1 KB · Views: 68
  • ErrorCoding.PNG
    3.6 KB · Views: 44

VJR

Well-Known Member
I tried to modify the code stage in collection contains value, but no luck as I don't know vb.net coding..

- Adding this line of code after found= True would give you the row number
RowIndex = row.Table.Rows.IndexOf(row) + 1

- RowIndex is an output parameter to the Code stage
View attachment 1534997991592.png

- You could delete all the unwanted code on the Groups collection like the 'for' loop which would unnecessary do the looping and consume more time.
- Likewise remove the groups collection output parameter and any reference to it from the code if you are able to.
- Also you can add code to exit the for loop as soon as the match is found and after the row index is calculated so as to avoid any unnecessary looping.
 
Deleted all the unwanted code and added the "Exit For" as soon as the match is found... Now its working exactly as expected.. Thank you very much for your help...
This is how the code looks now :
 

Attachments

  • WorkingCode.PNG
    20.3 KB · Views: 116
Top