Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi there,
Can anyone please educate me how Sub function works with a practical example?
I have seen the text in Help but would like to know some more practical examples and real world use cases.
You can find an example here: loop through to load all files from a folder and its subfolders?
In that example the code to recursively scans a folder and every subfolder is put in a sub. That allows the sub to be called with an initial root folder name and it will then recursively call itself with each subfolder as parameter.
That's the main use of subs: put code that you want to use multiple times in a script in a sub so you need only call the sub with the proper parameters instead of writing the same code over and over again in the script.