Hello, I found this forum while doing a search for VB NET related forums, as I am in quite a predicament at the moment, and would appreciate some help from an expert on how to do what I'm trying to do.

First off, this is for a class project, one that will make or break my grade depending on its performance, so I NEED to make sure I get it done right or else I'll have to retake the entire course. I've had no trouble up until this point, because frankly, our instructor never covered the stuff we're expected to do on this final project, instead he focused on things like designing menus and making forms change color, which we never have used, not even for our final project.

Anyway, the requirements are simple, yet at the same time, kinda rediculous.

Our primary task is to create a module called trig.vb that will manually perform Sine and Cosine calculations in Radians.

The catch is the picky manner in which he wants this done...

A Factorial Function must be written (As far as I can tell, doing this with any variable type aside from Double causes an overflow error, due to the fact the factorials go into the range of 99!)

The Sine procedure must be done as a subprocedure in trig.vb, called from the main form.

The Cosine function must be done similarly to the Sine function, but as a Function instead of a Subroutine.

Currently, I'm having trouble getting the Sine function to work, based on what I was given.

The Sine formula we were given is essentially as follows, the following symbols will be explained before I write the formula to ensure clarity

^=Exponential value

!=Factorial of number.

Okay, having said that, here's what the Sine Subroutine should calculate...

sin(x)=x-x^3/3!+x^5/5!-x^7/7!...-x^99/99!

As far as I can tell, this ALONE would overload the program, considering you're doing every factorial and exponent from 1 to 99 in increments of 2.

The cosine function is similar, but with all addition, and it goes in an order of 2, 4, 6, 8, etc all the way to 100.

Anyway, here's the code I have so far. If anyone could help me with getting this to work, and finishing up the rest of the program, I would be eternally grateful.

This is in the main.vb form, and calls the sine function...

Next up, we have the trig.vb Factorial Function and Sine Subroutine...

According to my assignment, the sine subroutine should return a value in the range of 0.5 when I enter .5322 as the value. I get something that rounds up to 0.02 instead. What's wrong with this?

First off, this is for a class project, one that will make or break my grade depending on its performance, so I NEED to make sure I get it done right or else I'll have to retake the entire course. I've had no trouble up until this point, because frankly, our instructor never covered the stuff we're expected to do on this final project, instead he focused on things like designing menus and making forms change color, which we never have used, not even for our final project.

Anyway, the requirements are simple, yet at the same time, kinda rediculous.

Our primary task is to create a module called trig.vb that will manually perform Sine and Cosine calculations in Radians.

The catch is the picky manner in which he wants this done...

A Factorial Function must be written (As far as I can tell, doing this with any variable type aside from Double causes an overflow error, due to the fact the factorials go into the range of 99!)

The Sine procedure must be done as a subprocedure in trig.vb, called from the main form.

The Cosine function must be done similarly to the Sine function, but as a Function instead of a Subroutine.

Currently, I'm having trouble getting the Sine function to work, based on what I was given.

The Sine formula we were given is essentially as follows, the following symbols will be explained before I write the formula to ensure clarity

^=Exponential value

!=Factorial of number.

Okay, having said that, here's what the Sine Subroutine should calculate...

sin(x)=x-x^3/3!+x^5/5!-x^7/7!...-x^99/99!

As far as I can tell, this ALONE would overload the program, considering you're doing every factorial and exponent from 1 to 99 in increments of 2.

The cosine function is similar, but with all addition, and it goes in an order of 2, 4, 6, 8, etc all the way to 100.

Anyway, here's the code I have so far. If anyone could help me with getting this to work, and finishing up the rest of the program, I would be eternally grateful.

This is in the main.vb form, and calls the sine function...

VB.NET:

```
Private Sub btnSine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSine.Click
If IsNumeric(txtMain.Text) Then
Dim result As Double
result = txtMain.Text
Sine(result)
result = Math.Round(result, 2)
txtMain.Text = result
End If
End Sub
```

VB.NET:

```
Function Factorial(ByVal N As Double) As Double
If N <= 1 Then
Return 1
Else
Return Factorial(N - 1) * N
End If
End Function
Public Sub Sine(ByRef value As Double)
Dim varSign As Double
Dim i As Double
Dim x As Double
x = value
varSign = -1
For i = 1 To 99 Step 2
value += (x ^ i / Factorial(i)) * varSign
varSign *= -1
Next i
End Sub
```

Last edited by a moderator: