Public Function Factorial (INTC AS Integer) AS STRING
ON Error Goto Myerr:
DIM INTA () AS INTEGER, INTT () AS INTEGER, I AS Integer
DIM J AS INTEGER, INTR AS INTEGER
Redim Inta (20), INTT (20)
IF INTC <2 THEN EXIT FUNCTION
INTR = 20
INTA (0) = 1
For i = 2 to intc
For j = 0 to intr
INTT (j) = INTA (j) * i
NEXT J
J = 0
DO Until J> Intr
INTA (j) = INTT (j) MOD 10
IF INTT (j)> = 10 THEN INTT (J 1) = INTT (J 1) INTT (J) / 10
J = J 1
Loop
Next I
Do While True
J = J - 1
IF INTA (j)> 0 THEN EXIT DO
Loop
For j = j to 0 step -1
Factorial = Factorial & INTA (j)
NEXT J
EXIT FUNCTION
Myerr:
If Err.Number = 9 THEN
INTR = INTR 20
Redim Preserve INTA (INTR)
Redim Preserve INTT (INTR)
Resume
Else
MsgBox "Unknow Err:" & Err.Description & ":" & Err.Number, vbcritical vbokonly
END IF
END FUNCTION