Hi guys, new to Uipath and going through the online courses. What is actually occuring when you change the first input field of the For Each loop from ‘Item’ to something else like ‘WinnerName’ as they do in one of the practice problems – which in this case ‘WinnerName’ is not a declared variable?
If you change “item” to other name, you can use it instead of “item” in the For Each loop. In this case, you don’t need to declear the variable in variable panel like “item”.
For example, it’s useful when you use double For-Each loop and distinguish outer loop item and inner one.
Hi Yoichi, and when you set the ‘Type Argument’ is that what that first input field name (Whether Item, or whichever name you give it) will be set as?
In general, we need to decide TypeArgument from type of collection we set in Values property.
For example, if you set
List<String> type variable in Values property, TypeArgument should be String.
Ok that makes sense, so is the ‘Item’ or whichever name we decide to give it is basically just a holder of a value, but it gets its type from the variable we input in the second input form? Or is its type completely agnostic so to speak?
@css you are almost there, only take note of - “item” is supposed to be one instance of iterable list/array of values. So if your values is of list of employee names(type string) than “item” would be name of first employee from the list of names for first, for each iteration and so on.
Similarly, if you wish to iterate over a list values/array/iterable like employee salary (double) than “item” would need to be of type “double” to hold one instance of employee salary being iterated in for each. So basically, type of item would depend of type of values you are holding.
In many case, we can decide the type as unique from collection. However, in some variable(class), it can be chose from multiple type. For example, In case of
List<FileInfo> , we can choose item type as FileInfo, FileInfoSystem, Object etc. It depends on program logic which type is better.
Thank you Yoichi and keshar that all makes sense.
@Yoichi, while going thru @css queries, it appeared to me what “Type Argument” would be required if say row being read as in “For Each Row” has columns to be treated differently like EmpName as String, but EmpDateOfBirth as Date and then say EmpSalary as Double!! - would Generic do? Provided we actually need to process records based some date logic and do some math for salary.
Yes, in DataTable, each DataColumn has type separately. However, in UiPath, For example, Excel-ReadRange Activity returns DatatTable which type of all the DataColumn is Object. To ensure to handle its type, perhaps we should use like the following expression.
dateTimeVar = DateTime.Parse(row("date").toString)
intSalary = CInt(row("saraly").toString)
Hope this helps you.