In certain cases in VBA (displaying the contents of folders, listing hierarchical data) writing a program which calls itself is by far the easiest way to go - this blog gives worked examples of 3 such recursive programs.
- Recursive Programming (this blog)
- Using Recursion to Display the Contents of a Folder
- Using Recursion to Show Hierarchical Breadcrumbs
- Using Recursion to Solve Factorials
Posted by Andy Brown on 20 February 2012 | no comments
The dictionary definition of Recursion says it all:
And if you didn't get (or like) that joke, here's a real definition: recursive programming is when you write a program which calls itself.
In practice there are few occasions when you'll actually use recursion - but when you do need it, it's nearly indispensable!
The examples this blog will show are:
|Folder contents||Recursively looping over folders and subfolders|
|Creating breadcrumbs||Creating menu breadcrumbs for hierarchical data|
|Calculating a factorial||Calculating the factorial of a number|
Of these, it would be much harder to write the first two examples without using recursion.