Multiple Loops

Hi All,

I have a condition where I need to download 36 different types of reports . These reports are stored in queue.

In this case to check each report and do the processing do I need to add 36 if else for each individual reports or there are any short cuts to it.

Hi @dutta.marina

There are Different ways you can approach this.

  1. Dictionary: Read the Excel file with the report names and convert it to a dictionary. The Key-Value pair could have the Report name as the key and the value could be whatever you wish to track. For example: {“ReportName1” : “Success”, “ReportName2”: “Processing”,…}
  2. Use the DataTable and For Each: Store the Names of the 36 reports in an Excel. You could loop through the reports and process them individually. For example:
Dim configData As DataTable = ReadExcel("config.xlsx")
For Each row As DataRow In configData.Rows
    If reportType = row("ReportType").ToString Then
        ' Execute the processing logic stored in the row
    End If
Next
  1. Use Switch Cases: But this will be similar to an If Else, you need 36 cases and it will not be dynamic (if the number of reports changes). But it’ll will faster than an If-Else ladder.

If you can explain the use-case further with more contaxt, I can provide a better answer. For now, I’d recommend 2nd solution

If this solves your issue, Do mark it as a solution.
Happy Automation :star_struck:

1 Like

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