Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Recursive Subs?

Can someone explain to me what recursive subs do. Mu understanding i
that it is a sub that in effect calls itself. Why would you ever nee
this? What woudl be an example of this

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Recursive Subs?

Hi
similar questions was aske prior this day. Here's a repost:
Frank
------

one reason is the use for recursive algorithms. e.g. calculation of the
factorial (e.g. 5! =1*2*3*4*5):
Function fact(i as integer) as long
If i = 0 then
fact = 1
else
fact = i*fact(i-1)
end if
end function
Of course you can achieve this without recursion but this way its
'easier' to read.

you may have a look at the following site:
http://cse.unl.edu/~dsadofs/Recursio...p?s=algorithms
for more information (or just do a google search for 'recursive
algorithms')





Can someone explain to me what recursive subs do. Mu understanding

is
that it is a sub that in effect calls itself. Why would you ever

need
this? What woudl be an example of this?


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Recursive Subs?

They are generally used when you don't know in advance how
big your loop size is
and have problems defining an efficient loop structure.
For an example, see my posting today
delete folder Feb 4 2004 8:55AM

There are some problems for which recursion is the more
elegant apppoach (e.g. code readability)
but "Out of stack space" can be a problem if the stack
space is unduly constrained.

Kevin Beckham

-----Original Message-----
Can someone explain to me what recursive subs do. Mu

understanding is
that it is a sub that in effect calls itself. Why would

you ever need
this? What woudl be an example of this?


---
Message posted from http://www.ExcelForum.com/

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Recursive Subs?

Recursion is as when a procedure calls itself. It can be an extremely useful
technique, but has to be used with care.

The biog advantage is that it allows you to process when you have absolutely
no idea how many levels of your particular item will occur, and so if you
are processing a data type, and amongst that you find another set of that
datatype, you can just branch out of your current processing, process the
new item by calling itself, and then pick up where you were at the end. And
this can be done a number of times.

The best example I have is a VBScript that deletes files from the temp
folder. It builds an array of files to delete. It start in the temp
directory, and adds to the array. If one of the files is a directory, it
recursively calls itself for this new directory, and so on. Thus, I don't
have to do any testing on the number of sub-folders, and sub-folders of
sub-folders, etc.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"ExcelMonkey " wrote in message
...
Can someone explain to me what recursive subs do. Mu understanding is
that it is a sub that in effect calls itself. Why would you ever need
this? What woudl be an example of this?


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Recursive Subs?

Can someone explain to me what recursive subs do.

To define recursion, we must first define recursion...


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Recursive Subs?

;-)
That's an illustration of what can go wrong if the recursive
algorithm is poorly designed.

loop, infinite - see infinite loop
infinite loop - see loop, infinite


"Vic Eldridge" wrote in message m...
Can someone explain to me what recursive subs do.


To define recursion, we must first define recursion...



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recursive Functions...maybe busboy10 Excel Worksheet Functions 0 March 28th 11 09:46 PM
How do you write a recursive formula in excel? DaveE Excel Worksheet Functions 1 April 5th 09 02:53 AM
recursive formula question a Excel Worksheet Functions 0 May 8th 07 09:29 AM
Recursive Functio help BigBobbo Excel Worksheet Functions 1 May 10th 06 07:23 PM
recursive sums Joe Excel Worksheet Functions 6 July 17th 05 09:45 AM


All times are GMT +1. The time now is 09:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"