=DEGREES(ATAN(## /##) convert to query (1 Viewer)

chugoleng@gmail.com

New member
Local time
Today, 12:14
Joined
May 14, 2017
Messages
3
Hi all,


like to ask for help, we have this formula from excel that I wanted to convert and apply to my simple form calculator in access


=DEGREES(ATAN(A6 /B6))


please help




-Mac
 

plog

Banishment Pending
Local time
Today, 14:14
Joined
May 11, 2011
Messages
11,638
We are more of a teaching to fish kind of forum than providing fish. So, what have you tried?

As general help--this is going to require you to write your own VBA function. You would pass it your 2 values, the function would do the calculation and return the value you want. The good news is, both those Excel functions do relatively simply math operations. Figuring out the logic shouldn't be too difficult, it will be the syntax that gives you issues.

Give it a shot and post back here what you have.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:14
Joined
Feb 28, 2001
Messages
27,146
First, Atn(x) is already an Access function. Be warned, however, that Arctangents can include infinity. Access, like any other computer in the world, really doesn't like infinity. How you handle infinities will be your problem.

Second, the Degrees function does not exist in Access but you could write a Public function in a General module and that function can be called in a query run from a DoCmd.RunSQL situation. The math is simple enough. If the proposed function would be available, Atn would be available in the same context.

Code:
Public Function ToDegrees( Rdns as Double) as Double
Dim X as Double
ToDegrees = Rdns * 180.0 / 3.141592653589793
End Function

Note also that this simplified version does not check for whether the angles are normalized in the range -pi to +pi, so if you put in an abominable number of radians, you will get an abominable number of degrees.

With this function, you could write "ToDegrees(Atn(A/B))" in a query and it should work as long as you don't care about those pesky infinities.
 

isladogs

MVP / VIP
Local time
Today, 20:14
Joined
Jan 14, 2017
Messages
18,209
Below are a list of trig functions missing from Access

I found these online recently & used some of them to add circles around locations on Google maps. See this post for screenshot: https://www.access-programmers.co.uk/forums/showpost.php?p=1579755&postcount=5

None are my own work - most of them came from http://www.devx.com/vb2themax/Tip/19024
The exception was the Atn2 function which I adapted from code for C# that I found somewhere else online

Code:
Option Compare Database
Option Explicit

'#####################################
'MISSING TRIG FUNCTIONS
'http://www.devx.com/vb2themax/Tip/19024

' arc sine
' error if value is outside the range [-1,1]

Function ASin(value As Double) As Double
    If Abs(value) <> 1 Then
        ASin = Atn(value / Sqr(1 - value * value))
    Else
        ASin = 1.5707963267949 * Sgn(value)
    End If
End Function

' arc cosine
' error if NUMBER is outside the range [-1,1]

Function ACos(ByVal Number As Double) As Double
    If Abs(Number) <> 1 Then
        ACos = 1.5707963267949 - Atn(Number / Sqr(1 - Number * Number))
    ElseIf Number = -1 Then
        ACos = 3.14159265358979
    End If
    'elseif number=1 --> Acos=0 (implicit)
End Function

' arc cotangent
' error if NUMBER is zero

Function ACot(value As Double) As Double
    ACot = Atn(1 / value)
End Function

' arc secant
' error if value is inside the range [-1,1]

Function ASec(value As Double) As Double
    ' NOTE: the following lines can be replaced by a single call
    '            ASec = ACos(1 / value)
    If Abs(value) <> 1 Then
        ASec = 1.5707963267949 - Atn((1 / value) / Sqr(1 - 1 / (value * value)))
    Else
        ASec = 3.14159265358979 * Sgn(value)
    End If
End Function

' arc cosecant
' error if value is inside the range [-1,1]

Function ACsc(value As Double) As Double
    ' NOTE: the following lines can be replaced by a single call
    '            ACsc = ASin(1 / value)
    If Abs(value) <> 1 Then
        ACsc = Atn((1 / value) / Sqr(1 - 1 / (value * value)))
    Else
        ACsc = 1.5707963267949 * Sgn(value)
    End If
End Function

Public Function Atn2(Y As Double, X As Double) As Double

'Arctangent of 2 values (lat/long)

  If X > 0 Then
    Atn2 = Atn(Y / X)
  ElseIf X < 0 Then
    Atn2 = Sgn(Y) * (Pi - Atn(Abs(Y / X)))
  ElseIf Y = 0 Then
    Atn2 = 0
  Else
    Atn2 = Sgn(Y) * Pi / 2
  End If

End Function
 

chugoleng@gmail.com

New member
Local time
Today, 12:14
Joined
May 14, 2017
Messages
3
First, Atn(x) is already an Access function. Be warned, however, that Arctangents can include infinity. Access, like any other computer in the world, really doesn't like infinity. How you handle infinities will be your problem.

Second, the Degrees function does not exist in Access but you could write a Public function in a General module and that function can be called in a query run from a DoCmd.RunSQL situation. The math is simple enough. If the proposed function would be available, Atn would be available in the same context.

Code:
Public Function ToDegrees( Rdns as Double) as Double
Dim X as Double
ToDegrees = Rdns * 180.0 / 3.141592653589793
End Function
Note also that this simplified version does not check for whether the angles are normalized in the range -pi to +pi, so if you put in an abominable number of radians, you will get an abominable number of degrees.

With this function, you could write "ToDegrees(Atn(A/B))" in a query and it should work as long as you don't care about those pesky infinities.




thank you so much The_Doc_Man


works like a charm!
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 20:14
Joined
Jul 9, 2003
Messages
16,272
thank you so much The_Doc_Man

Due to a bug in the forum software this message was "unapproved" (hidden) for some considerable time. I have just approved it. I hope no one has been inconvenience too much! The new forum software no longer has this bug, so this problem should not reoccur.
 

Users who are viewing this thread

Top Bottom