Factorial Function

Page 1 of 1

4 Replies - 4743 Views - Last Post: 08 January 2010 - 05:49 PM

#1 firebolt

• D.I.C Lover

Reputation: 93
• Posts: 5,561
• Joined: 20-February 09

Factorial Function

Posted 26 April 2009 - 11:25 PM

Description: An easier way to find the factorial of a number. Just place in the form and start.
```Public Function Factorial(ByVal Factor As Byte) As Variant

If Factor = 0 Then
Factorial = 1
Else
Factorial = Factor * Factorial(Factor - 1)
End If

Exit Function

Dim x As Single
x = InputBox("Number")
MsgBox Factorial(x)

End Sub

```

Is This A Good Question/Topic? 0

Replies To: Factorial Function

#2 firebolt

• D.I.C Lover

Reputation: 93
• Posts: 5,561
• Joined: 20-February 09

Re: Factorial Function

Posted 26 April 2009 - 11:25 PM

Description: An easier way to find the factorial of a number. Just place in the form and start.
```Public Function Factorial(ByVal Factor As Byte) As Variant

If Factor = 0 Then
Factorial = 1
Else
Factorial = Factor * Factorial(Factor - 1)
End If

End Function

Dim x As Single
x = InputBox("Number")
MsgBox Factorial(x)

End Sub

```

#3 iwantthependrive

Reputation: 0
• Posts: 12
• Joined: 15-February 09

Re: Factorial Function

Posted 03 May 2009 - 01:41 AM

You have not written "End Function". It should be after "Exit Function". it is giving an error otherwise.

#4 firebolt

• D.I.C Lover

Reputation: 93
• Posts: 5,561
• Joined: 20-February 09

Re: Factorial Function

Posted 03 May 2009 - 01:53 AM

Well Spotted. Wonder why whoever accepted it, didnt spot the error. Thanks but I dont think I can edit it now.

#5 boka3090

Reputation: 0
• Posts: 0
• Joined: 08-January 10

Re: Factorial Function

Posted 08 January 2010 - 10:08 AM

thank but not explain in the program.please when write program one by one line ,explain by the comment. thanks

#6 firebolt

• D.I.C Lover

Reputation: 93
• Posts: 5,561
• Joined: 20-February 09

Re: Factorial Function

Posted 08 January 2010 - 05:49 PM

Its a snippet, not a tutorial.