[Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register]

Author Message
edward233
General User

Joined: 11 Nov 2004
Posts: 16

 Posted: Tue Nov 08, 2005 3:08 pm    Post subject: Help with this macro Hi all I have this macro that wont run as a function but when i change it to a sub it works????? What it does is gives me a date code i can use to find out when spring is for any year. [code]Function spring(Year) y = Year jr = (y - 2000) / 1000 jdef = 2451623.80984 + 365242.37404 * jr + 0.05169 * jr ^ 2 - 0.00411 * jr ^ 3 - 0.00057 * jr ^ 4 jdes = 2451716.56767 + 365241.62603 * jr + 0.00325 * jr * jr + 0.00888 * jr ^ 3 - 0.0003 * jr ^ 4 jdeh = 2451810.21715 + 365242.01767 * jr - 0.11575 * jr ^ 2 + 0.00337 * jr ^ 3 + 0.00078 * jr ^ 4 jdew = 2451900.05952 + 365242.74049 * jr - 0.06223 * jr ^ 2 - 0.00823 * jr ^ 3 + 0.00032 * jr ^ 4 tf = (jdef - 2451545) / 36525 ts = (jdes - 2451545) / 36525 th = (jdeh - 2451545) / 36525 tw = (jdew - 2451545) / 36525 wf = 35999.373 * tf - 2.47 ws = 35999.373 * ts - 2.47 wh = 35999.373 * th - 2.47 ww = 35999.373 * tw - 2.47 lf = 1 + 0.0334 * Cos(wf * 3.14159265358979 / 180) + 0.0007 * Cos(2 * wf * 3.14159265358979 / 180) ls = 1 + 0.0334 * Cos(ws * 3.14159265358979 / 180) + 0.0007 * Cos(2 * ws * 3.14159265358979 / 180) lh = 1 + 0.0334 * Cos(wh * 3.14159265358979 / 180) + 0.0007 * Cos(2 * wh * 3.14159265358979 / 180) lw = 1 + 0.0334 * Cos(ww * 3.14159265358979 / 180) + 0.0007 * Cos(2 * ww * 3.14159265358979 / 180) sf1 = 485 * Cos((324.96 + 1934.136 * tf) * 3.14159265358979 / 180) + 203 * Cos((337.23 + 32964.467 * tf) * 3.14159265358979 / 180) + 199 * Cos((342.08 + 20.186 * tf) * 3.14159265358979 / 180) + 182 * Cos((27.85 + 445267.112 * tf) * 3.14159265358979 / 180) + 156 * Cos((73.14 + 45036.886 * tf) * 3.14159265358979 / 180) + 136 * Cos((171.52 + 22518.443 * tf) * 3.14159265358979 / 180) + 77 * Cos((222.54 + 65928.934 * tf) * 3.14159265358979 / 180) + 74 * Cos((296.72 + 3034.906 * tf) * 3.14159265358979 / 180) + 70 * Cos((243.58 + 9037.513 * tf) * 3.14159265358979 / 180) + 58 * Cos((119.81 + 33718.147 * tf) * 3.14159265358979 / 180) + 52 * Cos((297.17 + 150.678 * tf) * 3.14159265358979 / 180) + 50 * Cos((21.02 + 2281.226) * 3.14159265358979 / 180) sf2 = 45 * Cos((247.54 + 29929.562 * tf) * 3.14159265358979 / 180) + 44 * Cos((325.15 + 31555.956 * tf) * 3.14159265358979 / 180) + 29 * Cos((60.93 + 4443.417 * tf) * 3.14159265358979 / 180) + 18 * Cos((155.12 + 67555.328 * tf) * 3.14159265358979 / 180) + 17 * Cos((288.79 + 4562.452 * tf) * 3.14159265358979 / 180) + 16 * Cos((198.04 + 62894.029 * tf) * 3.14159265358979 / 180) + 14 * Cos((199.76 + 31436.921 * tf) * 3.14159265358979 / 180) + 12 * Cos((95.39 + 14577.848 * tf) * 3.14159265358979 / 180) + 12 * Cos((287.11 + 31931.756 * tf) * 3.14159265358979 / 180) + 12 * Cos((320.81 + 34777.259 * tf) * 3.14159265358979 / 180) + 9 * Cos((227.73 + 1222.114 * tf) * 3.14159265358979 / 180) + 8 * Cos((15.45 + 16859.074 * tf) * 3.14159265358979 / 180) sf = sf1 + sf2 ss1 = 485 * Cos((324.96 + 1934.136 * ts) * 3.14159265358979 / 180) + 203 * Cos((337.23 + 32964.467 * ts) * 3.14159265358979 / 180) + 199 * Cos((342.08 + 20.186 * ts) * 3.14159265358979 / 180) + 182 * Cos((27.85 + 445267.112 * ts) * 3.14159265358979 / 180) + 156 * Cos((73.14 + 45036.886 * ts) * 3.14159265358979 / 180) + 136 * Cos((171.52 + 22518.443 * ts) * 3.14159265358979 / 180) + 77 * Cos((222.54 + 65928.934 * ts) * 3.14159265358979 / 180) + 74 * Cos((296.72 + 3034.906 * ts) * 3.14159265358979 / 180) + 70 * Cos((243.58 + 9037.513 * ts) * 3.14159265358979 / 180) + 58 * Cos((119.81 + 33718.147 * ts) * 3.14159265358979 / 180) + 52 * Cos((297.17 + 150.678 * ts) * 3.14159265358979 / 180) + 50 * Cos((21.02 + 2281.226) * 3.14159265358979 / 180) ss2 = 45 * Cos((247.54 + 29929.562 * ts) * 3.14159265358979 / 180) + 44 * Cos((325.15 + 31555.956 * ts) * 3.14159265358979 / 180) + 29 * Cos((60.93 + 4443.417 * ts) * 3.14159265358979 / 180) + 18 * Cos((155.12 + 67555.328 * ts) * 3.14159265358979 / 180) + 17 * Cos((288.79 + 4562.452 * ts) * 3.14159265358979 / 180) + 16 * Cos((198.04 + 62894.029 * ts) * 3.14159265358979 / 180) + 14 * Cos((199.76 + 31436.921 * ts) * 3.14159265358979 / 180) + 12 * Cos((95.39 + 14577.848 * ts) * 3.14159265358979 / 180) + 12 * Cos((287.11 + 31931.756 * ts) * 3.14159265358979 / 180) + 12 * Cos((320.81 + 34777.259 * ts) * 3.14159265358979 / 180) + 9 * Cos((227.73 + 1222.114 * ts) * 3.14159265358979 / 180) + 8 * Cos((15.45 + 16859.074 * ts) * 3.14159265358979 / 180) ss = ss1 + ss2 sh1 = 485 * Cos((324.96 + 1934.136 * th) * 3.14159265358979 / 180) + 203 * Cos((337.23 + 32964.467 * th) * 3.14159265358979 / 180) + 199 * Cos((342.08 + 20.186 * th) * 3.14159265358979 / 180) + 182 * Cos((27.85 + 445267.112 * th) * 3.14159265358979 / 180) + 156 * Cos((73.14 + 45036.886 * th) * 3.14159265358979 / 180) + 136 * Cos((171.52 + 22518.443 * th) * 3.14159265358979 / 180) + 77 * Cos((222.54 + 65928.934 * th) * 3.14159265358979 / 180) + 74 * Cos((296.72 + 3034.906 * th) * 3.14159265358979 / 180) + 70 * Cos((243.58 + 9037.513 * th) * 3.14159265358979 / 180) + 58 * Cos((119.81 + 33718.147 * th) * 3.14159265358979 / 180) + 52 * Cos((297.17 + 150.678 * th) * 3.14159265358979 / 180) + 50 * Cos((21.02 + 2281.226) * 3.14159265358979 / 180) sh2 = 45 * Cos((247.54 + 29929.562 * th) * 3.14159265358979 / 180) + 44 * Cos((325.15 + 31555.956 * th) * 3.14159265358979 / 180) + 29 * Cos((60.93 + 4443.417 * th) * 3.14159265358979 / 180) + 18 * Cos((155.12 + 67555.328 * th) * 3.14159265358979 / 180) + 17 * Cos((288.79 + 4562.452 * th) * 3.14159265358979 / 180) + 16 * Cos((198.04 + 62894.029 * th) * 3.14159265358979 / 180) + 14 * Cos((199.76 + 31436.921 * th) * 3.14159265358979 / 180) + 12 * Cos((95.39 + 14577.848 * th) * 3.14159265358979 / 180) + 12 * Cos((287.11 + 31931.756 * th) * 3.14159265358979 / 180) + 12 * Cos((320.81 + 34777.259 * th) * 3.14159265358979 / 180) + 9 * Cos((227.73 + 1222.114 * th) * 3.14159265358979 / 180) + 8 * Cos((15.45 + 16859.074 * th) * 3.14159265358979 / 180) sh = sh1 + sh2 sw1 = 485 * Cos((324.96 + 1934.136 * tw) * 3.14159265358979 / 180) + 203 * Cos((337.23 + 32964.467 * tw) * 3.14159265358979 / 180) + 199 * Cos((342.08 + 20.186 * tw) * 3.14159265358979 / 180) + 182 * Cos((27.85 + 445267.112 * tw) * 3.14159265358979 / 180) + 156 * Cos((73.14 + 45036.886 * tw) * 3.14159265358979 / 180) + 136 * Cos((171.52 + 22518.443 * tw) * 3.14159265358979 / 180) + 77 * Cos((222.54 + 65928.934 * tw) * 3.14159265358979 / 180) + 74 * Cos((296.72 + 3034.906 * tw) * 3.14159265358979 / 180) + 70 * Cos((243.58 + 9037.513 * tw) * 3.14159265358979 / 180) + 58 * Cos((119.81 + 33718.147 * tw) * 3.14159265358979 / 180) + 52 * Cos((297.17 + 150.678 * tw) * 3.14159265358979 / 180) + 50 * Cos((21.02 + 2281.226) * 3.14159265358979 / 180) sw2 = 45 * Cos((247.54 + 29929.562 * tw) * 3.14159265358979 / 180) + 44 * Cos((325.15 + 31555.956 * tw) * 3.14159265358979 / 180) + 29 * Cos((60.93 + 4443.417 * tw) * 3.14159265358979 / 180) + 18 * Cos((155.12 + 67555.328 * tw) * 3.14159265358979 / 180) + 17 * Cos((288.79 + 4562.452 * tw) * 3.14159265358979 / 180) + 16 * Cos((198.04 + 62894.029 * tw) * 3.14159265358979 / 180) + 14 * Cos((199.76 + 31436.921 * tw) * 3.14159265358979 / 180) + 12 * Cos((95.39 + 14577.848 * tw) * 3.14159265358979 / 180) + 12 * Cos((287.11 + 31931.756 * tw) * 3.14159265358979 / 180) + 12 * Cos((320.81 + 34777.259 * tw) * 3.14159265358979 / 180) + 9 * Cos((227.73 + 1222.114 * tw) * 3.14159265358979 / 180) + 8 * Cos((15.45 + 16859.074 * tw) * 3.14159265358979 / 180) sw = sw1 + sw2 jdef = jdef + 0.00001 * sf / lf - 1 / (60 * 24) jdes = jdes + 0.00001 * ss / ls - 1 / (60 * 24) jdeh = jdeh + 0.00001 * sh / lh - 1 / (60 * 24) jdew = jdew + 0.00001 * sw / lw - 1 / (60 * 24) spring = jdef End Function[/code] any help appriciated
ms777
Super User

Joined: 07 Feb 2004
Posts: 1355

Posted: Tue Nov 08, 2005 3:30 pm    Post subject:

 Code: Sub Main Year1 = 2004 s = spring(Year1) End Sub
and it works... If you use 'year' instead of 'Year1', it does not work. I assume this is due to a naming conflict with the built in Year function
Dale
Super User

Joined: 21 Feb 2005
Posts: 1440
Location: Australia

Posted: Tue Nov 08, 2005 7:17 pm    Post subject:

Edward,
What I know about StarBasic can probably be written on a postage stamp. However, I copied your function into a calc module and called it from a spreadsheet [using the formula =spring(A1)]. I tested it for values of Year from 1900 to 2051 inclusive. It seems to work OK as a function. (At least - I get a number returned) Sample of input and output follows:
 Code: Year   =spring(Year) 1996   2450162.83 1997   2450528.08 1998   2450893.33 1999   2451258.57 2000   2451623.82 2001   2451989.06 2002   2452354.3

Is it running at all for you?
Is this the sort of return value you expect?
Can you expand a bit more on your problem?

Edit
Deleted comment to ms777 (erroneous - I should learn to read proper)
Spelling
_________________
Dale
To err is human, but to destroy your slippers in the process takes a real son of a bitch: Me!

OOo documentation from the source
http://documentation.openoffice.org
Guides, FAQ, How Tos
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT - 8 Hours Page 1 of 1

 Jump to: Select a forum OpenOffice.org Forums----------------Setup and TroubleshootingOpenOffice.org WriterOpenOffice.org CalcOpenOffice.org ImpressOpenOffice.org DrawOpenOffice.org MathOpenOffice.org BaseOpenOffice.org Macros and APIOpenOffice.org Code Snippets Community Forums----------------General DiscussionSite Feedback
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum