cancel
Showing results for 
Search instead for 
Did you mean: 

I want to understand how "Rename Collection Fields" works

sumire
Level 9
Hi,

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
------------------------------
1 BEST ANSWER

Helpful Answers

david.l.morris
Level 15
It doesn't really matter what order it renames the columns because it's matching up the column names between the Main_Collection and the New_Headers collection and then using the value in the first row of the New_Headers collection.

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

View answer in original post

2 REPLIES 2

david.l.morris
Level 15
It doesn't really matter what order it renames the columns because it's matching up the column names between the Main_Collection and the New_Headers collection and then using the value in the first row of the New_Headers collection.

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

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. 

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
------------------------------