What is the best practice for reusable code cover?

Hello,
for example, there are several places in my code where I access the Excel file. It can happen that the file is open by another process or is missing (someone delete it). I want to test during each access these situations.

My code should look like:

  • Set required variables
  • While (error or max attempts condition)
  • — Try
  • — --- Excel process block ← [Just this will change]
  • — Case
  • — --- If (file exists)
  • — --- — Alert - cannot be opened
  • — --- Else
  • — --- ​​​— Alert - does not exist

My idea is that everything but the Excel process block would be always the same. The Excel process block would be once Read Range, once Write Range and so on.

How can I do it to don’t have to copy and paste all this code and always cover the main one small working block by that ugly cover?

Thank you

The excel process block can be its own workflow. You can pass it parameters to make it versatile enough to do any type of Excel operation and then your overall code structure is the exact same no matter what the particular Excel operation is.

1 Like

If I understand you correctly, you mean something like I should have several workflows: The Main one (whole program), the Cover for working with Excel with Invoke block where I will inject by the parameter the third one the Excel process block?

For sure the Excel Process Block part you have above should be its own workflow, taking in parameters so I can read range/write range/etc. I don’t know enough about your overall program to tell you how I would structure the rest of it.

I think we understand each other. I’ll try it. Thank you @DanielMitchell

1 Like

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