By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,921 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

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

P: 3
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,9708795712695
14.9896229 * cos(0.525) = 7,51299393263617

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

Here is my code :
Expand|Select|Wrap|Line Numbers
  1. Public Class AdUL
  2.  
  3.     Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
  4.  Handles TextBox1.TextChanged
  5.  
  6.         TextBox3.Text = Val(TextBox1.Text) * 299792458 * 0.00000001
  7.         TextBox4.Text = Val(TextBox2.Text) * (Math.PI / 180)
  8.  
  9.     End Sub
  10.  
  11.     Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
  12.  Handles TextBox2.TextChanged
  13.  
  14.         TextBox3.Text = Val(TextBox1.Text) * 299792458 * 0.00000001
  15.         TextBox4.Text = Val(TextBox2.Text) * (Math.PI / 180)
  16.  
  17.     End Sub
  18.  
  19.     Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
  20.  Handles TextBox3.TextChanged
  21.  
  22.         Dim R As Decimal = Val(TextBox3.Text)
  23.         Dim a As Decimal = Val(TextBox4.Text)
  24.         TextBox5.Text = R * Math.Cos(a)
  25.         TextBox6.Text = R * Math.Sin(a)
  26.  
  27.     End Sub
  28.  
  29.     Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
  30.      Handles TextBox4.TextChanged
  31.  
  32.         Dim R As Decimal = Val(TextBox3.Text)
  33.         Dim a As Decimal = Val(TextBox4.Text)
  34.         TextBox5.Text = R * Math.Cos(a)
  35.         TextBox6.Text = R * Math.Sin(a)
  36.  
  37.     End Sub
  38.  
  39.  
  40. 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
Apr 27 '15 #1
Share this Question
Share on Google+
1 Reply


Seth Schrock
Expert 2.5K+
P: 2,941
Try using the CDec() function in your TextBox4 TextChanged event instead of the Val() function. Like this:
Expand|Select|Wrap|Line Numbers
  1. Dim R As Decimal = CDec(TextBox3.Text)
  2. Dim a As Decimal = CDec(TextBox4.Text)
  3. TextBox5.Text = (R * Math.Cos(a)).ToString()
  4. TextBox6.Text = (R * Math.Sin(a)).ToString()
  5.  
May 5 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.