By Kardi Teknomo, PhD .


< Previous | Next | VB Tutorial | Contents >

Recursive Procedure

Recursion is the ability of a routine to call itself. VB procedures (Sub and Function) can do recursive itself by calling its own name. It is also called nested procedures. Recursive procedure is very powerful way but quite difficult to debug.


1. Open a new project and type the following codes

Sub MyRecursive()
       Dim intX As Integer
       intX = intX + 1
       Call MyRecursive
End Sub
Private Sub Form_Click()
       MyRecursive
End Sub
                    

2. Run the program and see what happen
3. Try to debug the value of intX
4. Use menu: View-Call Stack to debug the procedure call

Some algorithm is recursive by nature (e.g. Dynamic Programming) and some algorithm can be translated from Recursive procedure to Repetition (using For-Next or Do-While-Loop). To define a good recursive procedure, you need to set the based value and code to get out of the recursion.

< Previous | Next | VB Tutorial | Contents >

Rate this tutorial or give your comments about this tutorial

This tutorial is copyrighted .