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