fires21
11-06-2016, 04:47 PM
This is the assignment that I was given, I have tried to do it over and over and this is what I have so far, yet I do not know where I keep going wrong:
The infinite series for the sine of x is
or, in expanded form,
Write a command button event procedure and another procedure called Sine to do the following:
· The event procedure will obtain the angle from the user using an input box. The user will provide the angle in degrees.
· The event procedure will call Sine, sending it the value of x.
· The Sine sub procedure will evaluate the Sine, using a loop to implement the series shown above.
· The number of terms used in the infinite series will be determined by comparing the summation with the result of the VBA sin(x) function. When the difference between the two is less than 1·10-10, enough terms have been used.
· The Sine procedure then returns the sine value to the event procedure.
· The event procedure gives the answer to the user in a suitable format in a message box.
Option Explicit
Private Sub CommandButton1_Click()
' Local Variables
Dim Series As Integer
Dim sin As Double
Dim Add As Boolean
Dim val As Range
Dim answer As Double
val = InputBox("Please Enter an Angle in Degrees", "Angle", 1)
Call Sine(val, sin)
answer = MsgBox("The sine of angle " & val & " is " & sin, , "Sine")
End Sub
Public Function Sine(val As Range, sin As Double)
Add = False
Do While True
Series = Series + 1
If Series Mod 2 <> 0 And Series > 1 Then
If Add Then
sin = sin + (val ^ Series) / dev(CLng(Series))
blnAddTerm = False
Else
sin = sin - (val ^ Series) / dev(CLng(intSeries))
blnAddTerm = True
End If
End If
If (DegInRads ^ Series) / Factorial(CLng(Series)) < 0.0000000001 Then Exit Do
Loop
SinBySeries = sin
End Function
Private Function dev(intNumber As Long) As Long
Dim i As Long
For i = intNumber To 0 Step -1
dev = dev + i
Next i
End Function
End Sub
The infinite series for the sine of x is
or, in expanded form,
Write a command button event procedure and another procedure called Sine to do the following:
· The event procedure will obtain the angle from the user using an input box. The user will provide the angle in degrees.
· The event procedure will call Sine, sending it the value of x.
· The Sine sub procedure will evaluate the Sine, using a loop to implement the series shown above.
· The number of terms used in the infinite series will be determined by comparing the summation with the result of the VBA sin(x) function. When the difference between the two is less than 1·10-10, enough terms have been used.
· The Sine procedure then returns the sine value to the event procedure.
· The event procedure gives the answer to the user in a suitable format in a message box.
Option Explicit
Private Sub CommandButton1_Click()
' Local Variables
Dim Series As Integer
Dim sin As Double
Dim Add As Boolean
Dim val As Range
Dim answer As Double
val = InputBox("Please Enter an Angle in Degrees", "Angle", 1)
Call Sine(val, sin)
answer = MsgBox("The sine of angle " & val & " is " & sin, , "Sine")
End Sub
Public Function Sine(val As Range, sin As Double)
Add = False
Do While True
Series = Series + 1
If Series Mod 2 <> 0 And Series > 1 Then
If Add Then
sin = sin + (val ^ Series) / dev(CLng(Series))
blnAddTerm = False
Else
sin = sin - (val ^ Series) / dev(CLng(intSeries))
blnAddTerm = True
End If
End If
If (DegInRads ^ Series) / Factorial(CLng(Series)) < 0.0000000001 Then Exit Do
Loop
SinBySeries = sin
End Function
Private Function dev(intNumber As Long) As Long
Dim i As Long
For i = intNumber To 0 Step -1
dev = dev + i
Next i
End Function
End Sub