Results 1 to 8 of 8

Thread: Trigometric Functions

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Location
    Upstate NY
    Posts
    210

    Trigometric Functions

    Okay,

    I have a sheet with the sine, cosine and tangent of the angesl 1 - 90 and i need to save it as a text file. Instead of typing them into the computer i decided to write a program to do it, what seemed to make a lot of sense. But it appears that vb's sin, cos, & tan functions are screwed up. For ex: vb says the sine of 1 is .8414..., while my sheet (and calculator) say .0174.... Any ideas?

    Thanks,
    -George
    < o >

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    My guess is that VBs functions are in radian mode, and you are entering degrees. I'm not sure how to fix it, unless you want to enter radians instead of degrees.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    You could do this:

    VB Code:
    1. MsgBox Format(Sin(45 * (3.14159 / 180)), "#.######")

    And just replace 45 for the angle you want. That should give you a close enough number.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Lively Member
    Join Date
    Jul 2002
    Posts
    87
    You can highlight Sin, Cos or Tan and hit the F1 key which will shortcut you to help on the function. It will tell you to multipy the value by PI/180 to convert radians to degrees and 180/PI to convert degrees to radians. The returned value from the above VB functions is in radians.

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by rba4321
    You can highlight Sin, Cos or Tan and hit the F1 key which will shortcut you to help on the function. It will tell you to multipy the value by PI/180 to convert radians to degrees and 180/PI to convert degrees to radians. The returned value from the above VB functions is in radians.
    That's what I did in the code above my post. If he doesn't have MSDN, F1 isn't going to do him any good.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    Try this:

    VB Code:
    1. Dim i As Integer
    2.  
    3. Private Sub Command1_Click()
    4. For i = 1 To 90
    5. Open App.Path & "\CST.txt" For Append As #1
    6. Print #1, "Cosine of" & " " & i & " =" & Format(Cos((i) * (3.14159 / 180)), "#.######")
    7. Print #1, "Sin of" & " " & i & " =" & Format(Sin((i) * (3.14159 / 180)), "#.######")
    8. Print #1, "Tan of" & " " & i & " =" & Format(Tan((i) * (3.14159 / 180)), "#.######")
    9. Close #1
    10. Next i
    11. End Sub

    I just used THs idea to print the data to a file.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Nightwalker83
    Try this:

    I just used THs idea to print the data to a file.
    Instead of opening the file 90 times, why not:

    VB Code:
    1. Dim i As Integer
    2.  
    3. Private Sub Command1_Click()
    4.     Open App.Path & "\CST.txt" For Output As #1
    5.         For i = 1 To 90
    6.             Print #1, "Cosine of" & " " & i & " =" & Format(Cos((i) * (3.14159 / 180)), "#.######")
    7.             Print #1, "Sin of" & " " & i & " =" & Format(Sin((i) * (3.14159 / 180)), "#.######")
    8.             Print #1, "Tan of" & " " & i & " =" & Format(Tan((i) * (3.14159 / 180)), "#.######")
    9.         Next
    10.     Close #1
    11. End Sub
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    Originally posted by The Hobo
    Instead of opening the file 90 times, why not:

    VB Code:
    1. Dim i As Integer
    2.  
    3. Private Sub Command1_Click()
    4.     Open App.Path & "\CST.txt" For Output As #1
    5.         For i = 1 To 90
    6.             Print #1, "Cosine of" & " " & i & " =" & Format(Cos((i) * (3.14159 / 180)), "#.######")
    7.             Print #1, "Sin of" & " " & i & " =" & Format(Sin((i) * (3.14159 / 180)), "#.######")
    8.             Print #1, "Tan of" & " " & i & " =" & Format(Tan((i) * (3.14159 / 180)), "#.######")
    9.         Next
    10.     Close #1
    11. End Sub
    Oops I put next and close around the wrong way.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

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