The ExICalendar library implements the iCalendar data format in accordance with the Internet Calendaring and Scheduling Core Object Specification (RFC 5545). The iCalendar format is used for exchanging calendaring and scheduling information, including events, to-dos, journal entries, and free/busy data, in a way that is independent of any specific calendar service or protocol.
The ICalendar library is a COM component that can be used in a registration-free manner, which means that it can be activated without being registered in the Windows registry. This is achieved through the use of an assembly manifest, which contains metadata about the component and its dependencies.
The control's assembly manifest is:
While running a sample you might encounter the following exception:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in exe
Additional information: Retrieving the COM class factory for component with CLSID failed due to the following error: 80040154.
The most probably you have installed the /COM x86 version ( 32-bit ) of
the component on a Windows x64 machine, so in order to prevent this error
do any of the following:
In VS - project properties - in the Build tab - platform target X86
( AnyCPU to X86 )
Install the x64 version of the component as well, as the
application runs as 64-bit on a Windows 64 machine
The ExCalendar component provides a calendar view for displaying and managing events. It supports recurring events based on the iCalendar standard, allowing events to repeat at regular intervals, such as daily, weekly, or monthly. The ICalendar library provides the RecurRange method, which generates a list of occurrences from a given recurrence expression. These occurrences can then be added to the ExCalendar component as individual events.
The idea of adding recurring events to ExCalendar consists in:
Handle the DateChanged event of the ExCalendar component
Collects the occurrences of the recurrence expression between
FirstVisibleDate, LastVisibleDate properties of the ExCalendar
component, using the RecurRange method of the ExICalendar library
For each occurrence found, add a new events using the Add method of
the Events collection of ExCalendar component
The following VB sample adds recurring events to ExCalendar:
Private Sub Calendar1_DateChanged()
DoEvents
With Calendar1
.BeginUpdate
Dim o As Variant
For Each o In CreateObject("Exontrol.ICalendar").RecurRange("DTSTART=20151201;FREQ=WEEKLY;BYDAY=FR", .FirstVisibleDate, .LastVisibleDate)
.Events.Add(o).Marker = True
Next
.EndUpdate
End With
End Sub
Private Sub Form_Load()
With Calendar1
.FirstDay = Monday
.AlignmentDay = CenterAlignment
.GridLineColor = RGB(128, 128, 128)
Calendar1_DateChanged
End With
End Sub
and you should get:
The following C++ sample adds recurring events to ExCalendar:
void C...Dlg::DateChangedCalendar1()
{
DoEvents();
EXCALENDARLib::ICalendarPtr spCalendar1 = GetDlgItem(IDC_CALENDAR1)->GetControlUnknown();
if ( spCalendar1 != NULL )
{
EXCALENDARLib::IEventsPtr spEvents = spCalendar1->Events;
spCalendar1->BeginUpdate();
EXICALENDARLib::IICalendarPtr spICal = ::CreateObject(L"Exontrol.ICalendar");
if ( spICal != NULL )
{
_variant_t vtRecurRange = spICal->GetRecurRange(L"DTSTART=20151201;FREQ=WEEKLY;BYDAY=FR",spCalendar1->FirstVisibleDate,spCalendar1->LastVisibleDate);
if ( V_VT( &vtRecurRange ) == ( VT_ARRAY | VT_DATE ) )
{
SAFEARRAY* pArray = V_ARRAY( &vtRecurRange );
DATE* pData = NULL;
if ( SUCCEEDED( SafeArrayAccessData( pArray, (LPVOID*)&pData ) ) )
{
long lowerBound = 0, upperBound = 0;
SafeArrayGetLBound(pArray, 1 , &lowerBound);
SafeArrayGetUBound(pArray, 1, &upperBound);
long nCount = upperBound - lowerBound + 1;
SafeArrayUnaccessData( pArray );
for ( long i = 0; i < nCount; i++, pData++ ) // iterate through returned values
spEvents->Add( *pData )->Marker = VARIANT_TRUE;
}
}
}
spCalendar1->EndUpdate();
}
}
BOOL C...Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
...
EXCALENDARLib::ICalendarPtr spCalendar1 = GetDlgItem(IDC_CALENDAR1)->GetControlUnknown();
if ( spCalendar1 != NULL )
{
spCalendar1->PutAlignmentDay(EXCALENDARLib::CenterAlignment);
spCalendar1->PutFirstDay(EXCALENDARLib::Monday);
spCalendar1->PutGridLineColor(RGB(128,128,128));
DateChangedCalendar1();
}
return TRUE; // return TRUE unless you set the focus to a control
}
The following C++ sample defines the CreateObject and DoEvents functions:
The ExG2antt/ExGantt component provides a Gantt chart view for displaying and managing tasks. It supports recurring tasks based on the iCalendar standard, allowing tasks to repeat at regular intervals, such as daily, weekly, or monthly. The ICalendar library provides the RecurRange method, which generates a list of occurrences from a given recurrence expression. These occurrences can then be added to the ExG2antt/ExGantt component as individual tasks.
The idea of adding recurring tasks to ExG2antt/ExGantt consists in:
Handle the DateChanged event of the ExG2antt component
Collects the occurrences of the recurrence expression between first
visible date and last visible date, using the RecurRange method of the ExICalendar library
For each occurrence found, add a new task using the AddBar method of the Items collection of ExG2antt component
The following VB sample adds recurring events to ExG2antt:
Function Max(ByVal a As Double, ByVal b As Double) As Double
Max = IIf(a < b, b, a)
End Function
Private Sub Form_Load()
With G2antt1
.BeginUpdate
.Columns.Add "Tasks"
.Items.AddItem "Every Friday, starting from 2015, Dec 1st"
With .Chart
.LevelCount = 2
.PaneWidth(0) = 224
.Bars("Task").Pattern = exPatternSolid
.FirstVisibleDate = #11/23/2015#
End With
.EndUpdate
End With
End Sub
Private Sub G2antt1_DateChange()
With G2antt1
.BeginUpdate
Dim o As Variant
For Each o In CreateObject("Exontrol.ICalendar").RecurRange("DTSTART=20151201;FREQ=WEEKLY;BYDAY=FR", .Chart.FirstVisibleDate, Max(.Chart.FirstVisibleDate + (1 + .Chart.PaneWidth(False) + .Chart.PaneWidth(True)) / .Chart.UnitWidth, .Chart.DateFromPoint(1, -1)))
.Items.AddBar .Items.FirstVisibleItem, "Task", o, o + 1, o
Next
.EndUpdate
End With
End Sub
and you should get:
A few notes:
The DateFromPoint(1, -1) property
determines the last visible date.
The Max(.Chart.FirstVisibleDate
+ (1 + .Chart.PaneWidth(False) + .Chart.PaneWidth(True)) / .Chart.UnitWidth,
.Chart.DateFromPoint(1, -1))), determines the maximum between
the last visible date if no columns section is displayed and the
currently last visible date
The initial FirstVisibleDate
should be called after filling the columns/items, so during the DateChange
event, the FirstVisibleItem property is
NOT zero, so adding bars is possible
The following C++ sample adds recurring events to ExG2antt:
The ExICalendar library is a COM component that can be used in a registration-free manner, which means that it can be activated without being registered in the Windows registry. This is achieved through the use of an assembly manifest, which contains metadata about the component and its dependencies.
The following methods:
RecurAll
RecurAllAsString
RecurRange
RecurRangeAsString
are limited to 16 occurrences only if:
running the trial version of the ExICalendar library (
Please check the Version property of the component, if contains DEMO )
RuntimeKey property has not been called, or using
invalid key, if running the registered version.
If you are using the registered version, you must call the RuntimeKey property immediately after creating the component.
The following VB sample shows how to use the RuntimeKey property:
Set iCal = CreateObject("Exontrol.ICalendar.1")
With iCal
.RuntimeKey = "..."
Debug.Print( .RecurAllAsString("DTSTART=19970805;FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1",255) )
End With
where "..." represents the runtime license key provided in the email you received when purchasing the component. If you have misplaced this email, please contact us to request your runtime license key.
The Load, LoadFile, and LoadFileU methods load iCalendar data into the component. The Root and Content properties provide access to the root and content components of the loaded format, respectively. Since each component can contain other components, the Count property of the Components collection returns the number of Component objects directly contained in the collection, excluding any nested components.
A) The following VB sample defines a recursive function that counts all Component objects, including nested components, by traversing the component hierarchy:
Function getComponentsCount(ByVal c As EXICALENDARLib.Component) As Long
Dim nCount As Long, i As EXICALENDARLib.Component
nCount = c.Components.Count
For Each i In c.Components
nCount = nCount + getComponentsCount(i)
Next
getComponentsCount = nCount
End Function
and you can call it using a code like: getComponentsCount(iCal.Content)
B) The following VB sample uses the AddComponent event to count all Component objects being loaded:
Dim nComponents As Long
Dim WithEvents iCal As EXICALENDARLib.ICalendar
Private Sub Form_Load()
Set iCal = New EXICALENDARLib.ICalendar
nComponents = 0
End Sub
Private Sub iCal_StartLoad()
nComponents = 0
End Sub
Private Sub iCal_AddComponent(ByVal NewComponent As EXICALENDARLib.IComponent)
nComponents = nComponents + 1
End Sub
Private Sub iCal_EndLoad()
Debug.Print (nComponents)
End Sub
where the nComponents member is increased each time the AddComponent event occurs.