[WD15] Calendar control

Startbeitrag von Jimbo am 28.12.2010 06:49


Hi,

I want to display the calendar week numbers to the right of the calendar control's rows (= weeks). In order to do so, I'd need to know the date of the Monday in the upper left corner of the window - no matter of grayed or not.

Is there a simple way to retrieve the date of the Monday in the upper left corner?

Kind regards,
Guenter

Antworten:

Jimbo

Simple? - not sure but this does work.
It is based on Monday being the first day displayed in the control.
I used it for a period start scenario, I guess in your case you will nedd an additional loop to calc the periods for the additional 5 rows.


ldDateNdx is Date = CalendarPosition(Calendar1) //Set to current displayed month
lnDayNdx is int = DateToDay(ldDateNdx) //Set to 1st day of current month
lnWeekNum is int

IF lnDayNdx 1 THEN //If day not Monday
ldDateNdx..Day -= lnDayNdx - 1 //Adjust date to 1st day of week displayed
END

lnWeekNum = WeekNumber(ldDateNdx) //Set week number for calendar start



Happy New Year

DerekT

von DerekT - am 28.12.2010 11:57

Hi Derek, thank you and a Happy New Year!

the calendar control has 7 rows.

- The first row of the calendar control is sometimes completely grayed (e.g. August 2011, Monday = 1st day of week).

- most times, the first day/s of the first row (= first displayed week) belong to the previous month.

In order to place the correct week number to the right of the control, it is crucial to know the full date of the Monday in the upper left corner. This one will be grayed and most times it will belong to the previous month. It's hard to mathematically find the correct Monday-date because the calendar control's internal algorithms are unpublished (Why is the first week of August 2011 shown in the second row?). So I wanted to know whether someone has a (API?) method that reveals the date of the first day.

Btw. WeekNumber(..) function doesn't work correctly. See my annotation to this function in WD15 web-Help system. See too: http://www.windev.at/html/calendarweeks.html

Kind regards,
Guenter


von Jimbo - am 28.12.2010 15:09
Jimbo

I do not know of an api available for this operation and even if there was one it would need to be tied into the control of the IDE being used - not all start with a Monday and most others seem to number their days from Sunday = 1.

That said the code I supplied will always return the date contained in the top left date element of the WD calendar control - which is what you are after.
You are correct about 01 Aug 2011 ocurring on line 2 (also occurs in Oct 2012, Apr 2013) and I can only surmise that PCS do this for asthetic reasons.
To overcome these instances I have added an ELSE statement.
I have just tested this through to the end of 2013 and the date returned has been correct in all cases.

I cannot comment on the WeekNumber function as I do not use this in my app.
Also, on my system anyway, the Calendar control only has 6 rows containing dates.

Revised code............

ldDateNdx is Date = CalendarPosition(Calendar1) //Set to current displayed month
lnDayNdx is int = DateToDay(ldDateNdx) //Set to 1st day of current month
lnWeekNum is int

IF lnDayNdx 1 THEN //If day not Monday
ldDateNdx..Day -= lnDayNdx - 1 //Adjust date to 1st day of week

ELSE
ldDateNdx..Day -= 7

END

lnWeekNum = WeekNumber(ldDateNdx) //Set week number for calendar start


Regards

Derek

von DerekT - am 28.12.2010 16:15
Quote
DerekT
Jimbo

I do not know of an api available for this operation and even if there was one it would need to be tied into the control of the IDE being used - not all start with a Monday and most others seem to number their days from Sunday = 1.

That said the code I supplied will always return the date contained in the top left date element of the WD calendar control - which is what you are after.
You are correct about 01 Aug 2011 ocurring on line 2 (also occurs in Oct 2012, Apr 2013) and I can only surmise that PCS do this for asthetic reasons.
To overcome these instances I have added an ELSE statement.
I have just tested this through to the end of 2013 and the date returned has been correct in all cases.

I cannot comment on the WeekNumber function as I do not use this in my app.
Also, on my system anyway, the Calendar control only has 6 rows containing dates.

Revised code............

ldDateNdx is Date = CalendarPosition(Calendar1) //Set to current displayed month
lnDayNdx is int = DateToDay(ldDateNdx) //Set to 1st day of current month
lnWeekNum is int

IF lnDayNdx 1 THEN //If day not Monday
ldDateNdx..Day -= lnDayNdx - 1 //Adjust date to 1st day of week

ELSE
ldDateNdx..Day -= 7

END

lnWeekNum = WeekNumber(ldDateNdx) //Set week number for calendar start


Regards

Derek


Hi Derek, thank you! I'll dig into it! And yes, of course, there are only 6 rows on the calendar control. I'm sorry about that. Kind regards, Guenter


von Jimbo - am 28.12.2010 16:23
Quote
DerekT
Jimbo

I do not know of an api available for this operation and even if there was one it would need to be tied into the control of the IDE being used - not all start with a Monday and most others seem to number their days from Sunday = 1.

That said the code I supplied will always return the date contained in the top left date element of the WD calendar control - which is what you are after.
You are correct about 01 Aug 2011 ocurring on line 2 (also occurs in Oct 2012, Apr 2013) and I can only surmise that PCS do this for asthetic reasons.
To overcome these instances I have added an ELSE statement.
I have just tested this through to the end of 2013 and the date returned has been correct in all cases.

I cannot comment on the WeekNumber function as I do not use this in my app.
Also, on my system anyway, the Calendar control only has 6 rows containing dates.

Revised code............

ldDateNdx is Date = CalendarPosition(Calendar1) //Set to current displayed month
lnDayNdx is int = DateToDay(ldDateNdx) //Set to 1st day of current month
lnWeekNum is int

IF lnDayNdx 1 THEN //If day not Monday
ldDateNdx..Day -= lnDayNdx - 1 //Adjust date to 1st day of week

ELSE
ldDateNdx..Day -= 7

END

lnWeekNum = WeekNumber(ldDateNdx) //Set week number for calendar start


Regards

Derek


Hi Derek, your code works GREAT now! Thank you! Guenter


von Jimbo - am 28.12.2010 17:16
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.