[Example] Aftermath calendar

Discuss the spreadsheet application
Post Reply
Obi
Posts: 16
Joined: Mon Sep 30, 2019 6:53 pm

[Example] Aftermath calendar

Post by Obi »

Hello,

the file is the central key of this post. I built a funny little app which is related to the OpenOffice schedule calendar macros.
The first tab is the GetNextBankDay app and the second holds instructions for also Excel users (calendar),
as shortly mentioned in the last post before. See in the second tab on how you can transform the calendar to Excel,
as well as to LibreOffice certainly.

Greetings Chris
Attachments
GetNextBankDay_+conversion.ods
(15.94 KiB) Downloaded 30 times
last_post.png
last_post.png (127.37 KiB) Viewed 1237 times
Apache OpenOffice 4.1.3, meanwhile 4.1.9 on Windows seven
link to my little football table helper tool here in the forum: ... and then /viewtopic.php?f=9&t=113077
2026 has come: =+(2+0*2*6)^(-(2^0)+2*6)-(20+SQRT(ABS(2-6))) | =2^(0+2)^6-2026+20-2^6
Obi
Posts: 16
Joined: Mon Sep 30, 2019 6:53 pm

Re: Aftermath calendar

Post by Obi »

Hello,

I have another file now... .
So, o.k., that should be much better, that should be much faster than the 'old' OO calendar.

I had problems with a mismatch year parameter value! I built up everything anew, and - voilà - in the debug(ger mode) i could see my idea was not so wrong,the parameter was there finally.
Now i have the problem: how can I - probably - sweep the R33-R404 cells after i had inserted a year (via choosing in B3 as ever) ? Does anyone have a clue about that? Because it's a whole ridiculous effort if the years typed in are not correct.

I used the Gauß'sche 'Wochentagsformel',which should better be called in german 'Jahresanfangswochentagsformel' lOL
The Gauß' formula first appeared in 1922 after some things were published then. He was a universal genius, and in Germany we had a d-mark value '10' with his portrait in the 90's. But it's said an anonymous person had already had this formula invented. (-> Wikip.)
Gauß was so sophisticated that he even didn't publish that formula in his lifetime...! Probably this was too primitive to him ^^

So does anyone know how to sweep/clear those cells (R33 to R404) of/from the predecessor ??
Thanks in advance(,i'm sure it's possible but i spent six hours yesterday, just to see that the year parameter was really defect/defunct/out of order, a few hours later)

Sorry my English.

I post the file

PS: Let's have another leap year construction ;-)
[EDITh: sorry,changed the file]
Attachments
calendar_loading_quicker___fuer_forum_.ods
not solved yet
(25.07 KiB) Downloaded 18 times
Apache OpenOffice 4.1.3, meanwhile 4.1.9 on Windows seven
link to my little football table helper tool here in the forum: ... and then /viewtopic.php?f=9&t=113077
2026 has come: =+(2+0*2*6)^(-(2^0)+2*6)-(20+SQRT(ABS(2-6))) | =2^(0+2)^6-2026+20-2^6
User avatar
MrProgrammer
Moderator
Posts: 5480
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Aftermath calendar

Post by MrProgrammer »

Obi wrote: Tue Nov 03, 2026 1:58 am How can I sweep R33-R404?
I interpret that question to mean you want to clear cells R33 to R404. An easy way is to record a macro. Then you can either call the macro from your StarBasic program, or you can copy the statements from the macro into your program, then delete the macro.
[Solved] Clear cell ranges C6:C29 and E6:E29
Favorite recorded Calc macros

If you don't understand how to use the OpenOffice API you should use a recorded macro. If you do understand the API you can use the clearContents method of the cell range. You probably want to pass the value 23 (1+2+4+16) (VALUE+DATETIME+STRING+FORMULA) to the method.
interface XSheetOperation
constants group CellFlags

Obi wrote: Tue Nov 03, 2026 1:58 am The Gauß' formula first appeared in 1922 after some things were published then.
I didn't study the your macros in detail, but I will guess that they want to calculate the date of Easter Sunday. The easiest way to do that is put formula =EASTERSUNDAY(B3) in some off-screen cell, say ZZ1, where B3 contains the year in decimal. Then your program can just read the value of ZZ1. But you can also call Calc's EASTERSUNDAY function directly from your StarBasic program using FunctionAccess → callFunction. A search of the Macros and UNO API forum for those terms will have many examples for you. When you use callFunction, pass the Calc function name as EASTERSUNDAY, not OSTERSONNTAG.
service FunctionAccess
interface XFunctionAccess

If this solved your problem please go to your first post use the Edit ✏️ button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.8, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
Obi
Posts: 16
Joined: Mon Sep 30, 2019 6:53 pm

Re: Aftermath calendar

Post by Obi »

Thank you MrProgrammer,

To explain: a start, with macros, with 2027. All working fine. Now we want 2028. Therefore we have to close the file first, then reopening without macros and adjusting to the year 2028 in B3,perhaps changing the BLand as well. We save & close again. We open, now with macros, and: everything well for 2028. And so on and on. But that's unsatisfying of course. All that should be done is a kind of ClearContents. But my API knowledge is too less. So perhaps there would exist a solution around of this line:
ThisComponent.Sheets().getByName("OO1500year_calendar").getCellRangeByName("R" & CStr(aster+32)).String = sDay2 & CalBankholidayName(aster)
(that's line 67 in the code) perhaps one can see what i tried,tried in line 68. Something like that, a refresh of emptiness of R33-R404 before (or after) this key line 67. Line 67 does a good job.

I'm still having my problems with the recorded macro.
I think I tried your links so far.
Perhaps you kicked me to the right direction I conclude
I see the next days what is to do.
Perhaps someone has one single WoW-that's-great-line which does the trick.
So far thank you | Sorry for my English
PS: Now i write '=R33' in B9, and the B9 stuff goes temporarily to B6 f.e.

My knowledge of the API is few. But there has to be an easy way i think (1,2 lines?.)

[EDITh:
To your last post, MrProgrammer:

Yes, I gave it a go (uno:ClearContents), but didn't succeed. Error value.
Maybe,maybe the construct :
getCellRangeByName("R" & CStr(aster+32)).String
is too complicated two times for the compiler
,cause I get an error value 'Property or Method not found : String'.

I wonder if someone has an experience with this Get..ByName IN LOOPS
One can only guess Greetings Chris

PS: it wasn't an easter problem, it's a clear/swept aside problem

Let's close topic,I'll do other things now
Thanks a lot!}

[EDITh]
it's not running that good anyway,but I would still like to add & leave necessary formulae concerning the second posting and this file ("not solved yet" file) in the thread here:

Code: Select all

	weakWeekday = GaussscherWochentag1JanuaryofYear
	Dim i as Integer, k as Integer
	For k = 84 to 118
		if CalBankholidayName(k) = "Ostersonntag" then
			if k < 111 then
				if isSchaltjahr = True then
					CalBankholidayName(k-50) = "Rosenmontag"
				else
					CalBankholidayName(k-51) = "Rosenmontag"
				end if
			else
				CalBankholidayName(k-48) = "Rosenmontag"
			end if
		end if
	Next k
	For i = 326 to 332
		if (CalBankholidayName(i) = "Buß- und Bettag") And Not (BLand2 = 13) then	'13 ist Sachsen
			CalBankholidayName(i) = ""
		end if
	Next i
	For aster = 1 to 372
(the first and last line stood to positioning for you)
The "Buß- und Bettag" is a "full" holiday (i don't use that else other) only for Saxony, which is "BLand" No.13.

I think it is/would be an interesting calendar model, as a whole.
My motivation was to get rid of 366 error messages when errors occur adjusting, to do it in an alternative way. So far,so good

In general, in correspondence see file One here and the Excel instructions! chapter 5, you could also now simplify (for (german) cal1500) C37 in OpenOffice to new (just if you like):
< code > =IF(C80=$C$5-48;"Mo Rosenmontag";IF(C80="";"";FUNCTNEO(C80;$V$4;$V$8))) < /code >

And: I've had some minor efforts/success concerning the problem with MrProgrammer`s linked lines:

Code: Select all

Sub webmanualbeispiel()
Dim Doc As Object
Dim Sheet As Object
Dim CellRange As Object
Dim Flags As Long

Doc = ThisComponent
Sheet = Doc.Sheets(0)
CellRange = Sheet.getCellRangeByName("R33:R404")

Flags = com.sun.star.sheet.CellFlags.STRING

CellRange.clearContents(Flags)

End Sub
That one (,some others don't,) does its trick just quick. Very good!

Remember key line 67 (now should be 86?)

PS: to YEARFRAC: It should be the constant 146.097 actually, and best method is parameter 1 at the end.

Thank you [/EDITh]
[EDITh] File: the mentioned transformation. Plus tab 2, that one runs without macros.
This is what i have achieved plus,an American calendar with the Gauß formula (in S3; tab 2).[/EDITh]
Attachments
fullautomatic_calendar_+newTabGaussProjekt.xlsm
(63.6 KiB) Downloaded 1 time
Last edited by Obi on Wed Dec 02, 2026 11:15 pm, edited 10 times in total.
Apache OpenOffice 4.1.3, meanwhile 4.1.9 on Windows seven
link to my little football table helper tool here in the forum: ... and then /viewtopic.php?f=9&t=113077
2026 has come: =+(2+0*2*6)^(-(2^0)+2*6)-(20+SQRT(ABS(2-6))) | =2^(0+2)^6-2026+20-2^6
User avatar
MrProgrammer
Moderator
Posts: 5480
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Aftermath calendar

Post by MrProgrammer »

Obi wrote: Tue Nov 03, 2026 6:58 am I'm still having my problems with the recorded macro.
I just now followed the steps in the Clear cell ranges C6:C29 and E6:E29 topic I linked for you and had no difficulty. You should try the steps from that topic before attempting something different. My macro recorded this (plus some REM statements). You should get the same macro statements if you followed the recording steps correctly.

sub T79234

dim document   as object
dim dispatcher as object
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "C6:C29"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
dispatcher.executeDispatch(document, ".uno:ClearContents", "", 0, Array())

dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "ToPoint"
args3(0).Value = "E6:E29"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args3())
dispatcher.executeDispatch(document, ".uno:ClearContents", "", 0, Array())

end sub

When I execute the subroutine the cells are cleared. You don't need to understand how the macro works. Just execute it. I think you can call the recorded macro from the macro you wrote, though I haven't tested that. I only tested running the macro from Calc → Tools → Macros. I am not volunteering to debug your macro. You are the programmer and that's your responsibility. I can perhaps point you in the right direction, for example, with links to API documentation for clearContents and callFunction in my previous post.

Originally, Easter was the first Sunday after the Full Moon that happens on or next after the spring equinox, and the date was announced each year by the pope. But the procedure was rather inconvenient, so the rules for finding the Easter date were fixed long ago by the Christian clergy. For the purposes of these rules, the Full Moon is reckoned according to an ecclesiastical computation and is not the real, astronomical Full Moon. Likewise, the equinox is always assumed to fall on March 21; actually, it can occur a day or two sooner. Long term variations in the length of a solar year and the orbits of the earth and moon would affect the true dates of the spring equinox or the spring full moon, but the church's calculation for Easter ignores these complications. So the following algorithm will determine Easter for any date in the Gregorian calendar. As with the recorded macro, you don't need to understand how the algorithm works, just execute it.

         Dividend      Divisor  Quotient  Remainder
Step 1   4-digit year     19                 A
Step 2   4-digit year    100       B         C
Step 3   B                 4       D         E
Step 4   8B+13            25       F
Step 5   19A+B−D−F+15     30                 G
Step 6   C                 4       H         I
Step 7   32+2E+2H−G−I      7                 J
Step 8   A+11G+19J       433       K
Step 9   G+J−7K+90        25       L
Step 10  G+J−7K+33L+19    32                 M

Easter's month is the quotient (L) from step 9 where 3 is March and 4 is April. The day of the month is the remainder (M) from step 10.
For 2026: A is 12, B is 20, C is 26, D is 5, E is 0, F is 6, G is 12, H is 6, I is 2, J is 2, K is 0, L is 4 (April), M is 5 (5th).

It's possible to perform these steps in StarBasic, however it is much easier to let Calc determine the date, since the OpenOffice developers have already implemented this calculation in Calc's EASTERSUNDAY function. The steps above return the same date as the EASTERSUNDAY function for any year which the function accepts (1583 to 9956). If you want to do Calc programming it is of course your responsibility to understand how dates work in Calc and also in StarBasic.

Obi wrote: Tue Nov 03, 2026 6:58 am My knowledge of the API is few.
It will be difficult to be successful with writing macros without that knowledge. Anyone can use recorded macros since OpenOffice writes them and there's no need to understand how they work. They just repeat the steps used to record them.

Writing your own macros is much, much harder, especially if you are not already an experienced programmer. It will be helpful to study this important book: OpenOffice Macros Explained. Page 473 has an example of using clearContents. Page 522 has an example for callFunction. Try to run the macros from the book before making any changes to them. You want to be able to begin with a working example. Then you can make changes to use these methods in your own macro.

If this solved your problem please go to your first post use the Edit ✏️ button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.8, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
Post Reply