Functionjc(ByValnAsInteger)AsLongDimiAsLongjc=1Fori=1Tonjc=jc*iNextEndFunctionPrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.ClickDimi,nAsIntegerDimsAsLong=0n=Val(InputBox("求1至n的階乘,請輸入n的值","n值")
)If(n>12)ThenMsgBox("n的值應不大于12,請重新輸入"
)ExitSubEndIfFori=1Tons=s+jc(i)NextiMsgBox("階乘之和="&Str(s)
)EndSub