- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-01-20 05:52 AM
Please tell me about the operation of "Rename Collection Fields" of VBO [Collection Manipulation].
This VBO will generally convert column names correctly, even if I specify the column names in a different order than the order in which they appear.
Microsoft Docs says that For Each ...Next loop does not determine the order of items in collection.
https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/for-each-next-statement
How does Blue Prism control the order in which items are retrieved?
Thanks,
------------------------------
Mitsuko
Asia/Tokyo
------------------------------
Mitsuko
Asia/Tokyo
------------------------------
Answered! Go to Answer.
Helpful Answers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-01-20 12:55 PM
It took me a minute, but I think I understand the code in that For Each loop, lol. Here's what I understand it to be doing... (inserting the for each loop for reference)
For Each C As DataColumn In Main_Collection.Columns Dim NewName As String = Cstr(New_Headers.Rows(0)(C.ColumnName)) If String.IsNullOrEmpty(NewName) Then Throw New ApplicationException("Blank field names are not acceptable") Else C.ColumnName = Trim(NewName) End If Next
The loop starts through each column in the Main_Collection. When it starts, it'll have one of the columns, and it starts by creating a variable 'NewName' to hold the new column name temporarily. The Cstr part looks a little confusing. If I explain this wrong, I'm trusting that someone more knowledgeable will correct me. But as I read it, inside the Cstr() parentheses, it is getting the name of the column that has just been retrieved by looping into the column names. the New_Headers.Rows(0) (C.ColumnName) part is getting the ColumnName from the first row (index 0) specifically from the column that has been chosen by the For Each C As DataColumn part of the loop declaration. After that, it just renames C.ColumnName with NewName.
Not sure if I was confusing there, but if you struggled with the same part I did, it was likely the 2-dimensional array/collection part where it does like Rows(0) (C.ColumnName). The (0) part of it is for the rows, and the C part is for the columns. By doing it like that, the code ensures it doesn't matter whether the order of the columns is the same or not.
------------------------------
Dave Morris
3Ci @ Southern Company
Atlanta, GA
------------------------------
Dave Morris, 3Ci at Southern Company
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-01-20 12:55 PM
It took me a minute, but I think I understand the code in that For Each loop, lol. Here's what I understand it to be doing... (inserting the for each loop for reference)
For Each C As DataColumn In Main_Collection.Columns Dim NewName As String = Cstr(New_Headers.Rows(0)(C.ColumnName)) If String.IsNullOrEmpty(NewName) Then Throw New ApplicationException("Blank field names are not acceptable") Else C.ColumnName = Trim(NewName) End If Next
The loop starts through each column in the Main_Collection. When it starts, it'll have one of the columns, and it starts by creating a variable 'NewName' to hold the new column name temporarily. The Cstr part looks a little confusing. If I explain this wrong, I'm trusting that someone more knowledgeable will correct me. But as I read it, inside the Cstr() parentheses, it is getting the name of the column that has just been retrieved by looping into the column names. the New_Headers.Rows(0) (C.ColumnName) part is getting the ColumnName from the first row (index 0) specifically from the column that has been chosen by the For Each C As DataColumn part of the loop declaration. After that, it just renames C.ColumnName with NewName.
Not sure if I was confusing there, but if you struggled with the same part I did, it was likely the 2-dimensional array/collection part where it does like Rows(0) (C.ColumnName). The (0) part of it is for the rows, and the C part is for the columns. By doing it like that, the code ensures it doesn't matter whether the order of the columns is the same or not.
------------------------------
Dave Morris
3Ci @ Southern Company
Atlanta, GA
------------------------------
Dave Morris, 3Ci at Southern Company
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
07-01-20 12:22 AM
Thanks that is exactly what I am confused.
Now I understand 'C.ColumnName' determines column and '0' gets new column name.
------------------------------
Mitsuko
Asia/Tokyo
------------------------------
Mitsuko
Asia/Tokyo
------------------------------
