OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Help with this user function

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc
View previous topic :: View next topic  
Author Message
edward233
General User
General User


Joined: 11 Nov 2004
Posts: 16
Location: Petawawa, Ontario Canada

PostPosted: Wed Dec 01, 2004 5:18 am    Post subject: Help with this user function Reply with quote

Im having problems with this user function cant seem to get it working.
Any help would be appriciated.



FUNCTION jday(year, month As Integer, day As Integer, hour As Integer,min As Integer, sec As Double, Optional greg) As Double

' returns julian day number given date in gregorian calender (greg=1)
' or julian calendar (greg = 0). If greg ommited, then Gregorian is assumed.
Dim a As Double
Dim b As Integer
'a = 10000 * year' + 100 * month + day
If (a < -47120101) Then MsgBox "Warning: date too early for algorithm"
If (IsMissing(greg)) Then greg = 1
If (month <= 2) Then
month = month + 12
Year = Year - 1
End If
If (greg = 0) Then
b = -2 + Fix((Year + 4716) / 4) - 1179
Else
b = Fix(Year / 400) - Fix(Year / 100) + Fix(Year / 4)
End If
a = 365 * Year + 1720996.5
jday = a + b + Fix(30.6001 * (month + 1)) + day + (hour + min / 60 + sec / 3600) / 24

End FUNCTION


Ed
Back to top
View user's profile Send private message Send e-mail
r_vinoya
Super User
Super User


Joined: 03 Dec 2003
Posts: 619
Location: Somewhere in the Philippines

PostPosted: Wed Dec 01, 2004 5:35 pm    Post subject: Re: Help with this user function Reply with quote

edward233 wrote:
Im having problems with this user function cant seem to get it working.
Any help would be appriciated.



FUNCTION jday(year, month As Integer, day As Integer, hour As Integer,min As Integer, sec As Double, Optional greg) As Double

' returns julian day number given date in gregorian calender (greg=1)
' or julian calendar (greg = 0). If greg ommited, then Gregorian is assumed.
Dim a As Double
Dim b As Integer
'a = 10000 * year' + 100 * month + day
If (a < -47120101) Then MsgBox "Warning: date too early for algorithm"
If (IsMissing(greg)) Then greg = 1
If (month <= 2) Then
month = month + 12
Year = Year - 1
End If
If (greg = 0) Then
b = -2 + Fix((Year + 4716) / 4) - 1179
Else
b = Fix(Year / 400) - Fix(Year / 100) + Fix(Year / 4)
End If
a = 365 * Year + 1720996.5
jday = a + b + Fix(30.6001 * (month + 1)) + day + (hour + min / 60 + sec / 3600) / 24

End FUNCTION


Ed


I just want to ask some questions...
What do you mean by "...cant seem to get it working?"

Does the macro has run-time error or is it not calculating as you wanted it to?

Also as tips,
1) it is better if you don't use variables that may be a special command (I don't really am sure if day, month, year and hour are special commands).
2) When your query is regarding Macros, it is better to ask this in Macros and API forum.
_________________
# : - )
Back to top
View user's profile Send private message
ooouser999
General User
General User


Joined: 04 Jan 2006
Posts: 5

PostPosted: Wed Jan 04, 2006 9:20 am    Post subject: Quirk in user defined functions Reply with quote

I had a problem getting user defined functions when I had a text label that was the same as the user defined function name.

For example:
- put an integer in A2.
- in cell C1 put '="FOO"' (no single quotes).
- in Cell C2 put '=foo(a2)' (no single quotes).

The user defined function code:

Function FOO(x)

FOO = x * 5

end Function

This would seem to work, until I closed the document and re-open it. Then
I would get an error, which was either a "#REF!" error or occasionally Err:509. OOo appears to have changed the function call in C2 to: ='FOO'(A2). If you delete the text in C1 and correct the function call in C2, all becomes well.
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Wed Jan 04, 2006 10:42 am    Post subject: Reply with quote

There is an option like "row/col-header auto-detection" in Tools>Options>Calc>Calculation. Your setup (label = function name) stumbles on this "feature".
Turn it off.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group