Code Master (Best place to find simplified and comprehensive resource of VB and ASP)

Recursive Programming is a technique by which a function call itself,
The source code is well commented so it's easier to understand

Place one textbox, command button and label control in your form
then copy the code below


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Label1.Text = Factorial(Val(TextBox1.Text))

End Sub

Private Function Factorial(ByVal num As Integer)

If num = 0 Then

'If num 0 then exit the function
Factorial = 1

Else

'Otherwise call itself, with argument
'1 lower than num, the cycle will repeat
'until num<>0

Factorial = (Factorial(num - 1)) * num

End If

End Function

 

Please read Terms & Conditions
Copyright © 2000 - 2005 Code Master. All rights reserved.
Best viewed with Internet Explorer 5.5 or above and with
800x600 or above resolution