求Sn=a+aa+aaa+……+aaa……a(n个a)的值,例如当a=2,n=4 时Sn=2+22+222+2222,a 和n 由键盘输出
这题应该怎么写,我一直想不好
Private Function SUMa(ByVal A As Long, ByVal N As Long) As Long
Dim I As Long, TempNum As Long
On Error GoTo SUMaError '发生错误跳转到SUMaError
If A < 1 Or N < 1 Or A > 10 Then GoTo SUMaError '参数错误则跳转
For I = 1 To N
TempNum = TempNum + Val(String(I, CStr(A)))
Next
SUMa = TempNum
Exit Function
SUMaError:
SUMa = -1 '发生错误时返回-1(调用参数错或是溢出)
End Function
[此贴子已经被作者于2007-5-22 22:00:00编辑过]