'Factorial calculator in windows Application
Public Class frmFactorialCalculator
Private Sub btnCalFactorial_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalFactorial.Click
Dim intNumber As Integer = 0
Dim IntFactorial As Integer = 0
Try
intNumber = Val(txtNumber.Text.Trim)
IntFactorial = fnGetFactorial(intNumber)
lblresult.Text = IntFactorial
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
'Factorial Function Codes
Private Function fnGetFactorial(ByVal num As Integer) As Integer
Dim intfac As Integer = 1
Dim i As Integer
For i = 2 To num
intfac *= i
Next
fnGetFactorial = intfac
End Function
End Class