Results 1 to 9 of 9

Thread: Trig Math Operators

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2014
    Posts
    6

    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

  2. #2
    Addicted Member
    Join Date
    Oct 2013
    Posts
    212

    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.

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2014
    Posts
    6

    Re: Trig Math Operators

    I made the modifications, however ArcCosine is the only working button option.

  4. #4
    Addicted Member
    Join Date
    Oct 2013
    Posts
    212

    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.

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    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

  6. #6
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    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

  7. #7
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    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

  8. #8
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    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

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Trig Math Operators

    Quote Originally Posted by kaliman79912 View Post
    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
  •  



Click Here to Expand Forum to Full Width