Creating dynamically new list(of string)


I need to create an arbitrary number of “List < String >” objects, dynamically. As one new “List < String >” for each single kind of given departments in a company. Later on, I’ll populate those lists with employees on each related department. Those departments are known (strings) and provided on a XLSX.

How is this possible to do, regarding the creation of an arbitrary number of lists of strings?

Thank you in advance.

Hi @tiagofreire
If you are saying that the number of lists you have to create is unknown till run time, then you can create one Dictionary<String, List> and create as many dynamic lists required. But in case if the count is pre defined, then you can create that number of List variables and assign records run time.

Please let me know if you need more info.
If you can elaborate the exact process along with example, it will be helpful to figure out solution.

It’s also possible that you are overthinking your approach. Maybe you don’t need a different list for each department during runtime.

For example:

Get departments
For each department
   Get list of employees
   Do something with list

As you can see, you do something with the list, therefore there’s no need to store it in memory. Then, you go to next department and overwrite it with the new list of employees.

Thank you for both.

I’m trying to develop an approach to solve a problem to randomly match a group of new onboarding employees to a list of mentors. The only limitation is that no mentor is allowed to match with a new employee from its organizational unit (“OU”). For each employee and mentor is known his OU, on a XLSX file.

The approach was to create a list for every single OU and delete the employee from it after randomly matching him with a mentor (on other OU, always), to avoid duplicate matches between mentors and employees or the same employee on more than one mentor.

Each mentor must have a minimum of 1 new employee match and a maximum defined in a int32 variable, pre-declared and pre-assigned (no more than 4).



I finally managed to achieve a first functional robot, only using 2 data structure types: 1x Datatable and 2x List(of Strings).

The robot (and a random dataset) is bellow and I’m open for any feedback or considerations about this first test. The computational complexity can be estimated around O(n)=n*log(n) for the best case scenario, I guess.

random.xlsx (19.1 KB) (13.7 KB)

Hi @tiagofreire

I have reviewed your code and below are my feedback-

  1. Naming Conventions - For variables and arguments, use short & descriptive names along with the data type of the value. Like,
    to store User Name in a variable, define variable as strUserName (str defines string)
    to store User Name in an argument, define argument as inStrUserName (str defines string, in defines that its a input argument)
  2. Activity Names and annotation - Add a descriptive name and annotation on what the activity is supposed to do for each activity (These will give readability to your code)
  3. Managing Business Exceptions
  • Before Accessing any file from system, check is the file exists (use path exists activity)
  • Post read range activity, check is the data table is generated and then the number of records in the data table. If the datatable object is not instantiated and you try to access the object, it will throw exception.
    For example, in the code you are using datatable.Rows.Count without checking instantiation.
  1. Exception Handling - You have used try-catch but in catch you are not checking why the exception is and also haven’t written any handlers.
  2. Code seggregation
  • Why in the tutor read range “A1:” +chr(65+2+numero_max_matches_por_buddy).tostring + ultima_linha_tutor.tostring is Used. You could have simply specified “A1”. When you dont specify an end cell, read range will retrieve the entire data.
  • In collaborator read range, end index you have used a variable and stored the value. If you already know the range and hard coding the value in the code, if that is not been used any where else, you can directly hard code directly in the read range as “A1:C100” instead of assigning to variable. When you create a variable or assign value, depending upon the datatype and value, memory will be allocated. Memory management is one of the key aspect in any programming.

Hope this is helpful. Let me know if you need more details.

1 Like

There’s some good reading on naming and clean code out there.

Using a Prefix to group like variables together is the best practice to be honest, since it allows you to search and get a list of the variables without needing to memorize every variable (and is faster). However, I think using the type as the prefix is outdated and there’s a better way. The problem with it you will find is that you may change the type of the variable, then you need to change the variable name all over. Now, on the other hand, if you change a singular string to a plural array of strings, then you may still need to change it to add an ‘s’.

I don’t know who came up with this method, but I have switched to using more meaningful prefixes, and let me explain. So let’s say you have an application like SAP. Every variable that is only associated with that application would start with ‘sap’ as the prefix.
For example, sapUsername sapPassword sapSelector sapWindow, et cetera. Then, if you have variables that go to another application like smtp, you would use smtpServer and smtpPort. And, any time you have an enumerable/array, your variable would simply be in plural form.

Also, I agree; you should be able to differentiate between variables and arguments by using a “in_”,“out_”, or “io_”. So for example, you might have variables called in_SapAssetNameCreds so you can feed an SAP login component which asset it will be using.

So essentially, the naming convention is in the form of: applicationPurpose where application is the group you are associating the variable to and Purpose is what the variable will be used for.

Also, creating habits is key. Everytime you add in a new activity, you must rename it. To keep it simple, just leave the generic activity name, then add the purpose of the activity next to it. For example, Click 'Login Button' or Type Into - Username. If you have two activities with the same name, then you are doing it wrong. You will find this very useful, because when an exception occurs, you will know the exact activity that failed; additionally, you will be able to understand what the code is doing while looking at it or fixing something.



@ClaytonM Thank you for the nice elaboration. But i still find is feasible to add a notation for datatype in my variables. When i will be working on a complex process, it gives me a complete readability on the variable without navigating to the variable panel. And of course, when we change the variable’s datatype, we need to update it in name as well. But if our architecture is correct, its a rare scenario that we change datatype for a variable.
Of course i agree to you point on mentioning the module specifications in the variable names. If you have different modules in the process, module specifications provide more readability. In case of a very small processes(single module), i would like to keep it simple as my process entirely running on one modules.

Once again, thank you for sharing the knowledge. :slight_smile: