ShelleyBelly
New Member
- Joined
- Mar 2, 2011
- Messages
- 44
Hello all,
I've the below user defined function which works well, however i would like to extract only part of the output using vba, in the below case it is the second output glon2. I know how to do this in a spreadsheet as a CSE function however i don't intend on putting the results into a spreadsheet and instead want to use it inside VBA to pass to another function.
direct_ell = Array(glat2, glon2)
Many thanks in advance,
Tom
I've the below user defined function which works well, however i would like to extract only part of the output using vba, in the below case it is the second output glon2. I know how to do this in a spreadsheet as a CSE function however i don't intend on putting the results into a spreadsheet and instead want to use it inside VBA to pass to another function.
direct_ell = Array(glat2, glon2)
Many thanks in advance,
Tom
Code:
Function direct_ell(glat1, glon1, a, f, faz, s)
r = 1 - f
tu = r * Tan(glat1)
sf = Sin(faz)
cf = Cos(faz)
If (cf = 0#) Then
b = 0#
Else
b = 2# * Atn2(tu, cf)
End If
cu = 1# / Sqr(1 + tu * tu)
su = tu * cu
sa = cu * sf
c2a = 1 - sa * sa
x = 1# + Sqr(1# + c2a * (1# / (r * r) - 1#))
x = (x - 2#) / x
c = 1# - x
c = (x * x / 4# + 1#) / c
D = (0.375 * x * x - 1#) * x
tu = s / (r * a * c)
y = tu
Do
sy = Sin(y)
cy = Cos(y)
cz = Cos(b + y)
E = 2# * cz * cz - 1#
c = y
x = E * cy
y = E + E - 1#
y = (((sy * sy * 4# - 3#) * y * cz * D / 6# + x) * D / 4# - cz) * sy * D + tu
Loop While (Abs(y - c) > 0.00000000000005)
b = cu * cy * cf - su * sy
c = r * Sqr(sa * sa + b * b)
D = su * cy + cu * sy * cf
glat2 = Atn2(D, c)
c = cu * cy - su * sy * cf
x = Atn2(sy * sf, c)
c = ((-3# * c2a + 4#) * f + 4#) * c2a * f / 16#
D = ((E * cy * c + cz) * sy * c + y) * sa
glon2 = Modlon(glon1 + x - (1# - c) * D * f)
direct_ell = Array(glat2, glon2)
End Function