How to set 0,1 as 0.1 on Sine and Cos function ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mKta
    New Member
    • Apr 2015
    • 3

    #1

    How to set 0,1 as 0.1 on Sine and Cos function ?

    Hello,

    When I use the Math.Cos and Math.Sin function I get wrong result because it get the value as 0,1 instead of 0.1.
    Here is an example

    14,9896229 * sin(0,525) = 14
    14,9896229 * cos(0,525) = 0

    (those values are imputed automatically)

    BUT

    14.9896229 * sin (0.525) = 12,970879571269 5
    14.9896229 * cos(0.525) = 7,5129939326361 7

    (those values I edited then manually while running the program)

    Here is my code :
    Code:
    Public Class AdUL
    
        Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
     Handles TextBox1.TextChanged
    
            TextBox3.Text = Val(TextBox1.Text) * 299792458 * 0.00000001
            TextBox4.Text = Val(TextBox2.Text) * (Math.PI / 180)
    
        End Sub
    
        Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
     Handles TextBox2.TextChanged
    
            TextBox3.Text = Val(TextBox1.Text) * 299792458 * 0.00000001
            TextBox4.Text = Val(TextBox2.Text) * (Math.PI / 180)
    
        End Sub
    
        Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
     Handles TextBox3.TextChanged
    
            Dim R As Decimal = Val(TextBox3.Text)
            Dim a As Decimal = Val(TextBox4.Text)
            TextBox5.Text = R * Math.Cos(a)
            TextBox6.Text = R * Math.Sin(a)
    
        End Sub
    
        Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
         Handles TextBox4.TextChanged
    
            Dim R As Decimal = Val(TextBox3.Text)
            Dim a As Decimal = Val(TextBox4.Text)
            TextBox5.Text = R * Math.Cos(a)
            TextBox6.Text = R * Math.Sin(a)
    
        End Sub
    
    
    End Class
    Note: I changed the decimal, interger, single and may more ... I get the same result ...
    Note2: I use Visual Basic from Visual Studio 2008

    Note3: I need results like the second example

    Can some help me ?

    Thank you
    Last edited by mKta; Apr 27 '15, 02:07 PM. Reason: some typos .. sorry if there are more left
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    Try using the CDec() function in your TextBox4 TextChanged event instead of the Val() function. Like this:
    Code:
    Dim R As Decimal = CDec(TextBox3.Text)
    Dim a As Decimal = CDec(TextBox4.Text)
    TextBox5.Text = (R * Math.Cos(a)).ToString()
    TextBox6.Text = (R * Math.Sin(a)).ToString()

    Comment

    Working...