Results 1 to 4 of 4
  1. #1
    rkalapura is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York
    Posts
    69

    Trigonometric Functions

    Hi,
    I want to do some calculations using trigonometric functions in a unbound text box in a form in Access 2010. But it is not giving me the right value. I think by default access gives the value in Radians. Text box formatted to 3 decimals. For example, when I enter =Sin(30) in the text box it gives me -0.988 but I need to have the value in degrees and I know that it is 0.500. Same way when I enter =Cos(30) in the box, it gives me .154, where as actual value of Cos(30) degree is 0.866. Help menu gives the following statement:



    "To convert degrees to radians, multiply degrees by pi/180. To convert radians to degrees, multiply radians by 180/pi." This gives close but not exact.

    How can I format my text box or set access to get the value in degree?

    Thank you in advance for your help and advise.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    I am not an expert, but this is the result I get.

    Code:
    Dim dblCos As Double
    Dim dblAngleRad As Double
    Dim dblAngleDeg As Double
    dblAngleDeg = 30
    dblAngleRad = dblAngleDeg * (3.14159 / 180)
    Debug.Print "dblAngleRad = " & dblAngleRad
    dblCos = 1 / Sin(dblAngleRad)
    Debug.Print "dblCos in Radians = " & dblCos
    dblCos = dblCos * (180 / 3.14159)
    Debug.Print "dblCos in Degrees = " & dblCos
    Results in
    dblAngleRad = 0.523598333333333
    dblCos in Radians = 2.00000153205215
    dblCos in Degrees = 114.591743597792

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    The number argument must be in radians. If 30 is degress, then:

    Cos(30 * (3.14159/180)) = 0.866025624916837

    The value returned by trig function is a ratio.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    PMFJI,

    I was playing around and came up with this function.

    Lets say you have 3 unbound text boxes on a form.

    In design view, name
    the first text box "tbTheAngle"; change the label caption to "Angle"
    the second text box "tbSine"; change the label caption to "Sine"
    and the third text box "tbCosine"; change the label caption to "Cosine"

    Paste the following function into a standard module:
    Code:
    Function GetSinCos(pTFunction As String, pdAngle As Double) As Double
       Const dPi As Double = 3.14159265358979
    
       Dim dRadians As Double
       Dim dResult As Double
    
       dResult = 0
    
       'convert Degrees to Radians
       dRadians = pdAngle * (dPi / 180)
    
       Select Case pTFunction
          Case "Sine"
             'calc Sine
             dResult = Sin(dRadians)
    
          Case "Cosine"
             'Calc Cosine
             dResult = Cos(dRadians)
             
          Case Else
             MsgBox "Not Sine or Cosine"
       End Select
    
       GetSinCos = dResult
    
    End Function
    In the control source for the text box "tbSine", enter
    =GetSinCos("Sine",[tbTheAngle])

    In the control source for the text box "tbCosine", enter
    =GetSinCos("Cosine",[tbTheAngle])

    Switch the form to standard view and enter 30 into the top text box (tbAngle).

    The value returned for the Sine should be 0.5
    and the value for the Cosine should be 0.866025403784439

Please reply to this thread with any new information or opinions.

Similar Threads

  1. F functions
    By dref in forum Access
    Replies: 1
    Last Post: 08-23-2012, 06:13 AM
  2. Dynamic functions
    By bubu678 in forum Programming
    Replies: 2
    Last Post: 11-09-2010, 09:55 PM
  3. Functions
    By Alex Motilal in forum Programming
    Replies: 2
    Last Post: 09-27-2010, 08:06 AM
  4. sum functions
    By trippers in forum Queries
    Replies: 2
    Last Post: 08-04-2010, 07:09 PM
  5. Functions
    By jamin14 in forum Programming
    Replies: 1
    Last Post: 03-25-2010, 08:16 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums