Explain the row(index) in a for each row loop

Hi all, hope all is well, I am following the Pracice 1 Calculate Sum, activity, there is a section where in a for each row, and assign activity is used and in the value field the following syntax is used:
row(0).To string, as per the the solution explenation, the row(Index), index is the column index, in this case column 0. But this is confusing, if you ask me row(0), as i would read it would be: give me the first element in the first row, row(1), giv e me the value of the row(1) and so on, Could i get a bit of an explanation? it would be much appreciated.

When you are working with datatables, remember that a datatable is a collection of datarows i.e an array of datarows. That collection of datarows may be assigned to a variable called rows (… note the plural). If we want to get the first row in our datatable variable, we write rows(0). Lets assume we store this item that we get in datarow variable called row, so

  • row = rows(0)

Each datarow consists of one or more datacolumns i.e each row is basically an array of datacolumns. So, if we want the value in the first column of our datarow, we write row(0).tostring. In this case, 0 is the index of the first column in our row. Instead of the index, we could use the column name is we knew it e.g. row(“BirthDate”).tostring.

Note rows is a collection of all datarow in the datatable and row is one specific datarow.

2 Likes

The default variable name to represent a row in your data table in a for each row activity is row, so using row(0) is giving you the value (as object type) of the first cell of this row.

1 Like

Thank you both for the explanation, i now understand it, thank you.

1 Like

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