Private Sub cmdE_Click()
cmdPi.Visible = False
cmdE.Enabled = False
'e^x= 1+x+x^2/2!+x^3/3!+...
'http://www.opensource.apple.com/darwinsource/10.2.6/bc-9/bc/bc/libmath.b
Dim x As Single
Dim buffer As String
Do
buffer = InputBox("Geef het getal x")
Loop Until IsNumeric(buffer)
x = CSng(buffer)
Dim i As Integer 'doorloper
i = 0
Dim resultaat As Double
Do
resultaat = resultaat + (x ^ i) / fac(i)
lblResultaat.Caption = resultaat
lblTermen.Caption = i
DoEvents
i = i + 1
Loop Until i = 170
End Sub
Function fac(n As Integer) As Double
If n = 0 Then
fac = 1
Exit Function
End If
Dim doorloper As Integer
fac = 1
For doorloper = 1 To n
fac = fac * doorloper
Next doorloper
End Function
Private Sub cmdPi_Click()
cmdPi.Enabled = False
cmdE.Visible = False
'Leibniz:pi/4= 1/1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + …
'http://membres.lycos.fr/villemingerard/Geometri/PiCalcul.htm
Dim i As Long
i = 1
Dim resultaat As Double
Do
If (i + 1) Mod 4 = 0 Then
resultaat = resultaat - 4 * 1 / i
Else
resultaat = resultaat + 4 * 1 / i
End If
lblResultaat.Caption = resultaat
lblTermen.Caption = i
DoEvents
i = i + 2
Loop
End Sub