Private Sub Command1_Click()
MsgBox (E(10 ^ (-8)))
End Sub
'p是精度
Private Function E(ByVal P As Double)
Dim I As Integer
Dim S As Double
Dim D As Double
I = 2
S = 2
D = 1
Do While D > P '10 ^ (-10)
D = 1 / F(I)
S = S + D
I = I + 1
Loop
E = S
End Function
'求阶乘
Private Function F(ByVal N As Integer) As Long
Dim I As Integer
Dim S As Long
S = 1
For I = 2 To N
S = S * I
Next I
F = S
End Function