-
May 8th, 2014, 10:25 PM
#1
Thread Starter
New Member
Trig Math Operators
Hey Guys! I'm not sure what is wrong with my code exactly. It all looks accurate with me. Hopefully, someone can spot the error. When I ran the program it just returns a 0 where I should have the sine, cosine, or tangent number. Soo here's my code:
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnASine_Click(sender As Object, e As System.EventArgs) Handles btnASine.Click
Dim sine As Double
Dim num As Double
Dim number As Double
num = Me.txtVal.Text
RadiansToDegrees(number)
sine = Math.Round(Math.Asin(number), 2)
Me.Label2.Text = "An angle with sine " & num & " is " & sine & " degrees. "
End Sub
Private Sub btnACo_Click(sender As Object, e As System.EventArgs) Handles btnACo.Click
Dim cosine As Double
Dim number As Double
Dim num As Double
num = Me.txtVal.Text
RadiansToDegrees(number)
cosine = Math.Round(Math.Acos(number), 2)
Me.Label2.Text = "An angle with cosine " & num & " is " & cosine & " degrees. "
End Sub
Private Sub btnATan_Click(sender As Object, e As System.EventArgs) Handles btnATan.Click
Dim tan As Double
Dim number As Double
Dim num As Double
num = Me.txtVal.Text
RadiansToDegrees(number)
tan = Math.Round(Math.Atan(number), 2)
Me.Label2.Text = "An angle with cosine " & num & " is " & tan & " degrees. "
End Sub
Function RadiansToDegrees(ByVal degree As Double)
Dim number As Double
number = Me.txtVal.Text
Return degree = number * (180 / Math.PI)
End Function
End Class
-
May 8th, 2014, 11:02 PM
#2
Addicted Member
Re: Trig Math Operators
First error:
Code:
Function RadiansToDegrees(ByVal degree As Double)
Dim number As Double
Get rid of dim number As double of the function
Change it to
Code:
Function RadiansToDegrees(ByVal degree As Double)As Double
number = Me.txtVal.Text
Return degree = number * (180 / Math.PI)
End Function
Last edited by Atenk; May 8th, 2014 at 11:08 PM.
-
May 8th, 2014, 11:15 PM
#3
Thread Starter
New Member
Re: Trig Math Operators
I made the modifications, however ArcCosine is the only working button option.
-
May 8th, 2014, 11:19 PM
#4
Addicted Member
Re: Trig Math Operators
JMC has provided a better answer to your post in "code it better".
Last edited by Atenk; May 8th, 2014 at 11:24 PM.
-
May 9th, 2014, 12:10 PM
#5
Re: Trig Math Operators
Ummm, perhaps I'm missing something, but the answer seems pretty obvious to me. You declare a variable number and a variable num. You put the value from the textbox into num, put nothing into number, then perform all the math on number, which is 0. In other words, the value goes into one variable, then you use the other variable for the math.
By the way, you should turn Option Strict ON for the project and fix the errors. Some of the lines you have will crash, since you are implicitly converting strings to doubles. The only safe way to do that is with Double.TryParse.
My usual boring signature: Nothing
-
May 9th, 2014, 12:36 PM
#6
Re: Trig Math Operators
also, RadiansToDegrees is a function but you are not using its return value, I think you are assuming that the parameter will change, but you pass it ByVal and then you never change it.
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
May 9th, 2014, 12:39 PM
#7
Re: Trig Math Operators
the line
Return Degree = number * (180 / Math.PI)
will return a boolean value and not a Double
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
May 9th, 2014, 12:52 PM
#8
Re: Trig Math Operators
Is this a school assignment?
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
May 9th, 2014, 02:45 PM
#9
Re: Trig Math Operators
Originally Posted by kaliman79912
the line
Return Degree = number * (180 / Math.PI)
will return a boolean value and not a Double
Good catch.
My usual boring signature: Nothing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|