Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
jblomqvist
Specialist
Specialist

Can anyone please educate me how Sub function works with a practical example?

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.

1 Reply
Gysbert_Wassenaar

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.


talk is cheap, supply exceeds demand