Simple Factorial function for VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #1

    Simple Factorial function for VB

    Here's a very simple function for VB (written in VB6) to calculate the factorial (!) of a number. Note that it is limited by the magnitude of the value which can be stored in the Long data type. (In fact, I believe it overflows at 13!)

    [CODE=vb]Public Function Factorial(ByVal bNum As Byte) As Long
    Dim I As Long
    If bNum <= 0 Then Exit Function
    Factorial = 1
    For I = 1 To bNum
    Factorial = Factorial * I
    Next
    End Function[/CODE]
Working...